更改UITableView标头色调颜色

时间:2013-03-04 09:27:10

标签: xcode uitableview header tint

我已经实现了以下代码,以便更改tableView中节标题的色调。我只是想改变颜色色调,而不是应用我自己的视图。但是,该应用似乎忽略了它,并且部分标题仍然以默认灰色显示。关于我可能做错什么的任何线索?非常感谢!

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

1 个答案:

答案 0 :(得分:2)

这是100%工作,您可以更改索引或标题文本颜色

- (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]];

}