Reputation: 497
Im trying to change the font colour on the table view header where it says California / New York. How do i do that?
On a black background the text needs to be white but cant figure this one out.
Thanks
Upvotes: 2
Views: 1368
Reputation: 6842
If you are trying to change the header color you can use this:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)];
// create the button object
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
//THE COLOR YOU WANT:
headerLabel.textColor = [UIColor blackColor];
headerLabel.highlightedTextColor = [UIColor whiteColor];
//THE FONT YOU WANT:
headerLabel.font = [UIFont boldSystemFontOfSize:20];
headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);
// If you want to align the header text as centered
// headerLabel.frame = CGRectMake(150.0, 0.0, 300.0, 44.0);
//THE TEXT YOU WANT:
headerLabel.text = <Put here whatever you want to display> // i.e. array element
[customView addSubview:headerLabel];
return customView;
}
Upvotes: 3
Reputation: 17958
You just don't have that much control over a table's default header styles. Have your table view's delegate return a custom view for each header instead bu implementing -tableView:viewForHeaderInSection:. That view could probably be just a UILabel with the text color set to whatever you like.
Upvotes: 1