4

当 Monotouch Dialog 类被实例化时,有没有办法设置字体?

[Section("This is the header")]

这将使用带有阴影的默认蓝色文本呈现,但我找不到该字体的设置位置。有没有办法覆盖它使用的字体和颜色?

4

2 回答 2

6

我为那些希望在整个解决方案中替换所有节标题的人找到了一个解决方案。在MonoTouch.Dialog中,有一个名为的类DialogViewController,用于使用反射 API 创建视图。在这里,有一个方法叫做GetViewForHeader(). section.HeaderView您可以创建自定义标签并将其发回,而不是只发回 normal 。

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;
}

请记住设置高度,手动或通过从标签获取高度。你也可以创建一个 custom UIView,但一个标签对我来说就足够了。

于 2011-02-09T13:58:47.187 回答
0

当您像这样使用 Section 时,您将使用 UITableView 标准渲染。

改变这一点的唯一方法是使用 Element API 而不是反射 API,并提供一个 UIView,您可以在其中自己绘制数据的内容。

于 2011-02-07T17:17:16.850 回答