有没有办法在实例化 Monotouch Dialog 类时设置字体?
[Section("This is the header")]
这将使用带阴影的默认蓝色文本进行渲染,但我找不到设置该字体的位置。有没有办法覆盖它使用的字体和颜色?
我为那些希望替换整个解决方案中的所有节标题的人找到了一个解决方案。在MonoTouch.Dialog
,有一个类名为DialogViewController
它在使用反射 API 创建视图时使用。在这里,有一个方法叫做GetViewForHeader()
。而不是仅仅发回正常的section.HeaderView
,您可以创建自定义标签并将其发回。
public override UIView GetViewForHeader (UITableView tableView, int sectionIdx)
{
var section = Root.Sections [sectionIdx];
if (!string.IsNullOrEmpty(section.Caption))
{
var label = new UILabel();
label.BackgroundColor = UIColor.FromRGB(89, 41, 17);
label.TextColor = UIColor.FromRGB(255, 206, 52);
label.ShadowColor = UIColor.Black;
label.ShadowOffset = new SizeF(0, 1f);
label.Font = UIFont.FromName("TitlingGothicFB Cond", 20);
label.Text = section.Caption;
return label;
}
return section.HeaderView;
}
public override float GetHeightForHeader (UITableView tableView, int sectionIdx)
{
if (!string.IsNullOrEmpty(section.Caption))
return 40f;
return -1;
}
请记住手动设置高度或通过从标签获取高度来设置高度。您还可以创建自定义UIView
,但一个标签对我来说就足够了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)