设置footerView UI TableView的背景颜色不起作用

时间:2019-07-31 04:58:53

标签: swift uitableview

我使用UIView()删除单独的行,并且可以,但是更改页脚视图的背景颜色不起作用。这是我的代码。有人可以解释为什么吗?非常感谢!

    let footerView = UIView()
    footerView.backgroundColor = UIColor(hexString: "#F7F9FC")
    myTableView.tableFooterView = footerView

2 个答案:

答案 0 :(得分:4)

这是因为footerView的大小为零。

let footerView =  UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 40.0))
footerView.backgroundColor = UIColor(hexString: "#F7F9FC")
myTableView.tableFooterView = footerView

答案 1 :(得分:1)

我认为您必须为页脚视图设置框架。如果仅创建UIView,则Apple的默认设置将创建带有框架的UIView为零。您需要设置宽度,高度,x,y才能在TableView中显示

 let frame = CGRect(x: 0, y: 0, width: yourWidthExpect, height: yourHeightExpect))
 let footerView =  UIView(frame: frame)

之后,您可以设置背景颜色并执行任何操作。