views:

552

answers:

1

Hello, i have pretty simple simple question (i hope so). How do i change the section header color in a UITableview from default blue to black transparent? Thanks in advance.

+3  A: 

you need to implement this method in the UITableViewDelegate protocol:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

Here is a link to the documentation

... and do something like this (sub in your own color):

UIView *section = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)] autorelease];
[section setBackgroundColor:[UIColor blackColor]];
return section;

You can also use the section integer to alternate colors or something similar. I think the default height for the sections is 22, but you can make it whatever you want. Is this what you meant by your question? Hope this helps.

Ryan Ferretti
Thanks, i thought there would some kind of trigger in IB to switch to black color. But anyway, thanks.
Simon D.
But please, cache those views. There is bug in UIKit causing to ask for header views when the tableView is being scrolled, so this method will get called for every pixel-offset while scrolling. 22px is indeed the default height.
JoostK