iphoneobjective-cuitableviewsectionheader

Changing color of section header in UITableview


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.


Solution

  • 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 *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)] autorelease];
    [sectionView setBackgroundColor:[UIColor blackColor]];
    return sectionView;
    

    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.