没有 Xamarin.Forms 的 UITableView Header 背景色

UITableView Header Background Color without Xamarin.Forms

我想更改 UITableView 中标题行的背景颜色。

我试过以下方法: 1:在“TableView”->“Section Index”->“Background”中设置Xcode-Designer 2:作为 ViewDidLoad 中的代码:TableView.TintColor = UIColor.Black 和 TableView.BackgroundColor = UIColor.Black;

什么都没发生,背景还是浅灰色..

我在这里找到的所有内容都是 Xamarin.Forms,但我没有使用 Xamarin.Forms!

您可以使用自己的自定义视图和覆盖方法 GetViewForHeader。您可以参考下面的代码,它可以改变Header Background Color和text color:

public override UIView GetViewForHeader(UITableView tableView, nint section)
{
    UIView view = new UIView();
    view.BackgroundColor = UIColor.Yellow;
    view.Frame = new CoreGraphics.CGRect(0, 100, 200, 50);

    UILabel label = new UILabel();
    label.Frame = view.Bounds;
    label.Text = "test";
    label.TextColor = UIColor.Red;

    view.Add(label);

    return view;
}