gpt4 book ai didi

ios - 如何更改表格 View 中部分标题的颜色?

转载 作者:IT王子 更新时间:2023-10-29 05:14:55 24 4
gpt4 key购买 nike

这是我目前拥有的。

enter image description here

如何引用它以便更改文本颜色以匹配我的索引列表? sectionForSectionIndexTitle 可以很好地添加正确的章节标题,但是如何访问标题元素呢?

或者这是不可能的,我需要重新绘制 View 并使用 viewForHeaderInSection 添加它?

最佳答案

你可以使用UITableViewDelegate的方法之一

swift3 及以上

  func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
if let headerView = view as? UITableViewHeaderFooterView {
headerView.contentView.backgroundColor = .white
headerView.backgroundView?.backgroundColor = .black
headerView.textLabel?.textColor = .red
}
}

objective-c

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
if([view isKindOfClass:[UITableViewHeaderFooterView class]]){
UITableViewHeaderFooterView * headerView = (UITableViewHeaderFooterView *) view;
headerView.textLabel.textColor = [UIColor RedColor];
}
}

作为引用,我从 here 中获取了模型答案

关于ios - 如何更改表格 View 中部分标题的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39614268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com