更改颜色标题UITable静态部分

时间:2012-12-14 10:30:59

标签: xamarin.ios tableview

我的应用程序中有两个UITable静态部分,两个标题都不同。 必须更改标题的颜色,因为自定义背景。

如何在我的MonoTouch应用程序中执行此解决方案(link)?

因为我使用的是静态部分,所以我没有UITableViewSource可以用来做任何事情。

我的解决方案(感谢Krumelur)

[Export("tableView:viewForHeaderInSection:")]
UIView GetViewForHeaderInSecion (UITableView tableview, int section)
{
    UIView view = new UIView (new RectangleF (0, 0, 300, 0));
    view.BackgroundColor = UIColor.Clear;

    UILabel label = new UILabel (new RectangleF (15, 5, 300, 25));
    label.BackgroundColor = UIColor.Clear;
    label.TextColor = UIColor.White;
    label.ShadowColor = UIColor.Black;
    label.ShadowOffset = new SizeF(0, 1);
    label.Font = UIFont.BoldSystemFontOfSize(18);

    if (section == 0) {
        label.Text = "First section";
    } else {
        label.Text = "Second section";
    }

    view.AddSubview(label);
    return view;
}

1 个答案:

答案 0 :(得分:2)

您必须在控制器中导出丢失的方法。类似的东西:

[Export("tableView:viewForHeaderInSection:")]
UIView GetViewForHeaderInSection(UITableView tableview, int section
{
// return your UIView with whatever background color here
}

请注意,您无法更改预定义视图的颜色,但必须返回整个视图。