我有一个简单的表格 View ,我可以更改单元格的颜色,但是当尝试更改表格 View (背景部分)的颜色时它不起作用...我通过 Storyboard 尝试过...有人可以吗帮助
最佳答案
首先在viewDidLoad
中设置tableView的背景色如下:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.backgroundColor = UIColor.lightGrayColor()
}
现在添加这个方法:
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.backgroundColor = UIColor.clearColor()
}
在 Swift 3 中,使用下面的方法代替上面的方法:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.backgroundColor = UIColor.lightGray
}
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.backgroundColor = UIColor.clear
}
关于iOS Swift - 如何更改表格 View 的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30679701/