ios - 如何在 UITableView 中更改基于索引的部分通用颜色

标签 ios objective-c uitableview

通常我的屏幕显示是这样的:

enter image description here

当我使用这段代码时

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

我的输出是这样的:

enter image description here

我的部分索引文本不可见。我知道节标题 View 添加了我的自定义 View 。我想更改部分标题颜色并显示索引文本。

@Khawar 回答我得到这个输出

enter image description here

最佳答案

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

}

输出:

enter image description here

关于ios - 如何在 UITableView 中更改基于索引的部分通用颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21453828/

相关文章:

ios - 当移动网络浏览器使用自定义 URL 启动 native iOS 应用程序时,会传递哪些元数据?

ios - DispatchQueue.main.async 阻塞主线程

ios - 检测 _which_ 手指触摸 iOS 设备上的屏幕

swift - 在 UIableView 中设置要突出显示的默认单元格

ios - 如何在不使用 xcode 的情况下创建类似 .xcappdata 的内容?

ios - UITableView 中的 UITextField 与 DatePicker 的 InputView

ios - 通过应用程序在 iPhone 上存储数据的限制

iphone - 关于添加到数组的对象中对象的保留计数问题,Obj-C

ios - 到达 UITableView 底部后加载更多

ios - Swift:使用 prepareForSegue 将 UIView 容器的高度设置为嵌入式 UITableView 的高度