ios - 如何为 UITableView 标题设置颜色文本颜色

标签 ios swift uitableview

在我更新到 IOS 13 之前,我有一个可以正确显示的应用。

在旧版本的应用程序(iOS 13 之前)中,标题文本颜色显示正确。见下文。

现在标题显示如下:

我没有改变任何东西,所以我假设苹果方面发生了一些变化。 这就是我设置标题文本颜色的方式:

func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    let header = view as! UITableViewHeaderFooterView
    header.textLabel?.textColor = Styles.greyColor()
    header.backgroundView?.backgroundColor = Styles.mainColor()
    header.textLabel?.font = UIFont.systemFont(ofSize: 13, weight: UIFont.Weight.light)
}

它要求的颜色是这样创建的:

static func greyColor() -> UIColor{
    return uicolorFromHex(0x9B9B9B)
}

static func mainColor() -> UIColor {
    // blue background
    //return uicolorFromHex(0x222C45)
    return uicolorFromHex(0x1B2337)
}

这可能已经被讨论过,但我似乎找不到任何关于它的最新帖子。

最佳答案

我能够通过添加来解决这个问题:

header.contentView.backgroundColor = Styles.mainColor()

希望这对处于相同情况的任何人都有帮助。

关于ios - 如何为 UITableView 标题设置颜色文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58054801/

相关文章:

ios - 复数 NSLocalizedString 中的字符串参数

ios - 通用链接不适用于网页链接

swift - 为什么在添加单个文档时 firestore 监听器返回 .added 两次?

ios - 自定义 UITableView 标题设置背景颜色失败

ios - 如何检查元素是否可点击

iphone - iOS:如何将控件放置在父容器的中心?

ios - UITapGestureRecognizer - 让它在触地时工作,而不是触地?

ios - 基于对多关系中的属性检索 NSManagedObject 的最快方法

ios - 滚动 UITableView 时如何创建 NSLayoutConstraint

iphone - 在 UITableView 中执行 commitEditingStyle 时如何制作 'delete-button' 的自定义 View