I currently have a UITableView with multiple sections.
The header for each section is defined in the delegate like this (code adjusted for testing purposes):
[Export("tableView:viewForHeaderInSection:")]
public UIView GetViewForHeader(UITableView tableView, nint section)
{
var header = tableView.DequeueReusableHeaderFooterView("TestHeaderIdentifier");
if(header == null)
header = new UITableViewHeaderFooterView(new NSString("TestHeaderIdentifier"));
header.TextLabel.Text = "Section " + section;
header.TextLabel.TextColor = UIColor.Red;
header.ContentView.BackgroundColor = UIColor.FromRGB(124, 255, 190);
//.. Other customizations
return header;
}
This seems to work fine except for one bit, the TextColor of the label.
The above code results in the following:
The background color and text itself are applied fine, but the text color remains set to the default colour. What could be the cause of this issue?
I've already tried:
RegisterClassForHeaderFooterViewReuse
) Both to no avail.
I would give your two solutions:
First, change the textColor in WillDisplayHeaderView
function:
public override void WillDisplayHeaderView(UITableView tableView, UIView headerView, nint section)
{
if (headerView is UITableViewHeaderFooterView)
{
UITableViewHeaderFooterView v = headerView as UITableViewHeaderFooterView;
v.TextLabel.TextColor = UIColor.Red;
}
}
Second, you can use your own custom views instead of UITableViewHeaderFooterView
:
public override UIView GetViewForHeader(UITableView tableView, nint section)
{
//var header = tableView.DequeueReusableHeaderFooterView("TestHeaderIdentifier");
//if (header == null)
// header = new UITableViewHeaderFooterView(new NSString("TestHeaderIdentifier"));
//header.TextLabel.Text = "Section " + section;
//header.TextLabel.TextColor = UIColor.Red;
//header.ContentView.BackgroundColor = UIColor.FromRGB(124, 255, 190);
////.. Other customizations
//return header;
UIView view = new UIView();
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.