I’m working witha simple tableview but I need to modify the font size for the text in the group header.
I’ve found this question on stackoverflow eferencing the tableview methods to override but I’m looking for an example of how I might modify the actual headers font size once I implement this method
Note: I’m able to modify the height of the header itself using interface builder but the font size appears to require some objective-c to modify this
Thank you in advance
Edit
here is what I have so far -it’s not throwing an exception but the header itself doesn’t show the text or font size I set on the label itself
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView* x = tableView.tableHeaderView;
UILabel* y = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 310, 0)];
y.font = [UIFont boldSystemFontOfSize:12.0];
y.text = @"ha";
[x addSubview:y];
[y release];
return x;
}
The header for a table may be set to any subclass of
UIView. In particular, you can create aUILabel, set the text with your desired font size, then make the label theheaderView.Three potential problems with your edit:
Did you remember to implement
tableView:heightForHeaderInSection:?The height of your
UILabelis currently0.When this method is called,
tableView.tableHeaderViewmay not yet be defined.My approach would be to declare
UILabel *headerLabeland then add this toviewDidLoad:Then have