UITableView 页脚和页眉背景颜色比指定的深 [英] UITableView Footer and Header Background color darker than specified
本文介绍了UITableView 页脚和页眉背景颜色比指定的深的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为 TableviewController 设置样式,我希望将背景设置为非常浅的灰色,将单元格设置为白色,并带有相同灰色阴影的粗边框.但是,在我设置背景和页眉颜色后,它们都变成了非常深的阴影(颜色代码没问题,页脚比页眉深).
I'm Trying to style a TableviewController, and I wish to set the background to a very light gray and the cells to white, with thick borders of the same gray shade. However, after I set background and header colors, they both turn to be a very dark shade (the color code is ok, and the footer is darker than the header).
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.backgroundView?.backgroundColor = gainsBoro
self.tableView.backgroundColor = gainsBoro
self.tableView.separatorStyle = .none
self.tableView.tableFooterView = UIView()
}
并设置标题颜色:
override func tableView(_ tableView: UITableView, willDisplayHeaderView view:UIView, forSection: Int) {
if let headerTitle = view as? UITableViewHeaderFooterView {
headerTitle.textLabel?.textColor = UIColor.black
headerTitle.backgroundView?.backgroundColor = gainsBoro
}
}
结果:
有什么想法吗?
推荐答案
尝试标题:
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView()
headerView.backgroundColor = gainsBoro
return headerView
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 15
}
和它的页脚:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.backgroundView?.backgroundColor = gainsBoro
self.tableView.backgroundColor = gainsBoro
self.tableView.separatorStyle = .none
let footerView = UIView()
footerView.backgroundColor = gainsBoro
self.tableView.tableFooterView = footerView
}
并删除此代码:
override func tableView(_ tableView: UITableView, willDisplayHeaderView view:UIView, forSection: Int) {
if let headerTitle = view as? UITableViewHeaderFooterView {
headerTitle.textLabel?.textColor = UIColor.black
headerTitle.backgroundView?.backgroundColor = gainsBoro
}
}
这篇关于UITableView 页脚和页眉背景颜色比指定的深的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文