Change UITableView header tint color

Álvaro Morales Navarro picture Álvaro Morales Navarro · Mar 4, 2013 · Viewed 7.4k times · Source

I have implemented the following code in order to change the tint of the section headers in a tableView. I just want to change the color tint, not to apply a view from my own. The app, however, seems to ignore it and the sections headers keep being displayed with the default gray. Any clue about what could I be doing wrong? Thanks a lot!

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    [[tableView headerViewForSection:section] setTintColor:[UIColor brownColor]];
    return [tableView headerViewForSection:section];
}

Answer

codercat picture codercat · Jan 30, 2014

this is work 100% and you can change your index or header text color

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    view.tintColor = [UIColor blueColor];

    // if you have index/header text in your tableview change your index text color 
    UITableViewHeaderFooterView *headerIndexText = (UITableViewHeaderFooterView *)view;
    [headerIndexText.textLabel setTextColor:[UIColor blackColor]];

}