【问题标题】:Changing the background color of UITableViewHeaderFooterView is not supported. Use the background view configuration instead不支持更改 UITableViewHeaderFooterView 的背景颜色。改用背景视图配置
【发布时间】:2021-06-07 01:19:57
【问题描述】:

我使用 xib 自定义 headerView 并将默认背景颜色设置为此 headerView,我总是收到此警告。如何解决?谢谢。

这些属性不适合我。

【问题讨论】:

标签: ios swift uitableview xib


【解决方案1】:

不太确定,你说的我已经试过是什么意思,从你发布的代码 sn-p 显然你没有,你可以做这个 tableView 委托或在你的 headerView 本身的awakeFromNib

guard let header =
        detailTableView.dequeueReusableHeaderFooterView(withIdentifier: "DetailListHeaderView") as? DetailListHeaderView else { fatalError("could not create headerView") }
        let backgroundView = UIView(frame: header.bounds)
        backgroundView.backgroundColor = UIColor(white: 0.5, alpha: 0.5)
        header.backgroundView = backgroundView
        //other codes of yours
        return header

【讨论】:

  • 谢谢,但我已经尝试过了,但不起作用,它显示了同样的警告。
【解决方案2】:

我发现将 IB 中的背景颜色属性设置为默认值可以解决警告问题。但是,我的顶级项目是视图,而您的是单元格,它可能具有不同的默认颜色,这会导致警告。

【讨论】:

    猜你喜欢
    • 2013-03-14
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 2014-07-06
    • 2013-08-08
    相关资源
    最近更新 更多