xamarin.ios - 更改颜色标题 UITable 静态部分

标签 xamarin.ios tableview

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

如何在我的 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;
}

最佳答案

您必须导出 Controller 中缺少的方法。类似于:

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

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

关于xamarin.ios - 更改颜色标题 UITable 静态部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13876880/

相关文章:

c# - ios monotouch 的 UIProgressView 跟踪下载状态

c# - 解析 JSON.net 中的枚举

xamarin.ios - 自定义 Xamarin.Forms 布局

ios - 删除后重新加载应用程序时, TableView 中的核心数据条目会出现

java - TableView列数据设置为小数点后2位

java - JavaFX 中的复选框单元格工厂 + Tableview

xamarin - 如何符号化 Xamarin Forms iOS 项目中的崩溃/错误日志?

c# - 更改导航栏标题的颜色

uitableview - 将 UITableView 单元格连接到另一个 UITableView

ios - 我的代码有什么问题。我正在尝试为表格 View Controller 着色