通常我的屏幕显示是这样的:
当我使用这段代码时
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
[headerView setBackgroundColor:[UIColor whiteColor]];
return headerView;
}
我的输出是这样的:
我的部分索引文本不可见。我知道节标题 View 添加了我的自定义 View 。我想更改部分标题颜色并显示索引文本。
@Khawar 回答我得到这个输出
最佳答案
这是 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]];
}
输出:
关于ios - 如何在 UITableView 中更改基于索引的部分通用颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21453828/