我正在以编程方式将UIView放在TableView Header中。
但是,标题视图已被“导航控制器”栏阻止,并且高度不会变大。
这是我的代码:
let headerView = UIView()
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
headerView.backgroundColor = UIColor(red: 0.000, green: 0.749, blue: 1.000, alpha: 1.00)
headerView.frame = CGRect(x: 0, y: 100, width: view.frame.width, height: 200)
return headerView
}
工作原理:
TableView加载。
出现一个“蓝色”标题,看起来大约10px大,并卡在TableView的顶部
该“蓝色”标题被导航控制器栏阻止。
什么不起作用:
“蓝色”标头未更改其高度。
“蓝色”标题不会降低。
最佳答案
应该是这样!
var headerView = UIView()
headerView.backgroundColor = UIColor(red: 0.000, green: 0.749, blue: 1.000, alpha: 1.00)
headerView.frame = CGRect(x: 0, y: 100, width: view.frame.width, height: 200)
self.tableView.tableHeaderView = headerView // Here goes the UIView for the header