【问题标题】:How to set the color text color for a UITableView header如何为 UITableView 标题设置颜色文本颜色
【发布时间】:2019-09-23 01:54:33
【问题描述】:

我有一个应用程序在更新到 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)
}

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

【问题讨论】:

  • 在 UITableViewHeaderFooterView 的摘要下它说:“您还可以将可选的背景视图分配给背景视图属性。”这不是我想要做的吗?
  • 你可以试试header.backgroundView?.backgroundColor = .clear
  • 同样的结果,谢谢你的建议。
  • 我可以通过添加解决这个问题:header.contentView.backgroundColor = Styles.mainColor()

标签: ios swift uitableview


【解决方案1】:

我可以通过添加来解决这个问题:

header.contentView.backgroundColor = Styles.mainColor()

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

【讨论】:

  • 好答案!我认为您也可以接受自己的答案(为您添加绿色检查+更多代表),对吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-10
  • 1970-01-01
  • 2013-02-18
  • 2014-04-26
  • 1970-01-01
  • 2011-07-17
相关资源
最近更新 更多