21

Greetings! I know that UITableView sectionHeaderHeight is only used for grouped tables, but I'll ask anyway (in case there's some way to do this that isn't obvious) ...

Is there a way to change the section header height (and with it, the font/size) for a NON-grouped table?

Hoping "yes" or at least a "maybe" ... but fearing it might be a "no". Have at it, folks.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Joe D'Andrea
  • 5,141
  • 6
  • 49
  • 67

2 Answers2

49

Yes.

Use this delegate method:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 44;
}

Of course, change as appropriate. There's of course the one for footer as well:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 44;
}
Aleksandar Vacić
  • 4,433
  • 35
  • 35
  • Thanks! Of course, I tried that in iPhone OS 3.0, but it didn't seem to work. It would just stay the same height. However, it's working just fine in 3.1, so I suspect we chalk this one up to "bug fix" or "pilot error" on my part. (Always happy to admit if it's the latter, but I'm just not sure _why_ it wasn't working earlier if this isn't a bug fix. Even if I had sectionHeaderHeight in play, it would be overridden by tableView:heightForHeaderInSection:. Hmm ...) – Joe D'Andrea Sep 29 '09 at 13:12
1

At least since iOS 9 (tested) UITableView.sectionHeaderHeight is working for plain table views (non-grouped) as well!

You will get the default header height (usually 22.0).

Of course the table views delegate might have customized this default value in its tableView:heightForHeaderInSection: method.

The following code snippet gives the height of a defined section header:

CGFloat headerHeight = self.tableView.sectionHeaderHeight;
if ([self.tableView.delegate respondsToSelector:@selector(tableView:heightForHeaderInSection:)]) {
    // possibly custom header height
    headerHeight = [self.tableView.delegate tableView:self.tableView heightForHeaderInSection:indexPathForCell.section];
}
LaborEtArs
  • 1,938
  • 23
  • 27