iOS Swift - 如何更改Table View的背景颜色? [英] iOS Swift - How to change background color of Table View?
本文介绍了iOS Swift - 如何更改Table View的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的表格视图,我可以更改单元格的颜色,但是当试图改变表格视图(背景部分)的颜色时它不起作用......我通过故事板试了一下......有人可以请帮助
I have a simple table view, I can change the colors of cells, but when trying to change the color of Table View (Background part) it is not working... I tried it via Storyboard... Can someone please help
推荐答案
首先在 viewDidLoad
中设置tableView的背景颜色下面:
First set the background color of the tableView in viewDidLoad
like below:
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 中,请使用以下方法代替以上一个:
In Swift 3, use below methods instead of above one:
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 - 如何更改Table View的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文