不支持更改 UITableViewHeaderFooterView 的背景颜色。改用背景视图配置

时间:2021-03-09 06:45:39

标签: ios swift uitableview xib

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

enter image description here

enter image description here

这些属性对我不起作用。

1 个答案:

答案 0 :(得分:1)

不太确定,我已经尝试过你的意思是什么,从你发布的代码片段中可以清楚地看出你还没有,你可以做这个 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