xcode 更改 UITableView 标题色调颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15198244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:53:59  来源:igfitidea点击:

Change UITableView header tint color

xcodeuitableviewheadertint

提问by álvaro Morales Navarro

I have implemented the following code in order to change the tintof 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!

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

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

回答by codercat

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

这是 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]];

}