如何在 iOS 上修改 TableView 项目的背景颜色?
修改表视图项目的背景颜色不同于修改表视图的背景颜色。新手程序员经常将这两件事混为一谈,在本帖中,我们将学习如何修改 TableView 项目的背景颜色,即单元格。
因此,让我们开始吧。
如需修改表视图单元格的背景颜色,你应当修改单元格的 contentView.backgroundColor 属性。
Add the below code in your cellForRowAt indexPath method, cell.contentView.backgroundColor = UIColor.cyan
你的方法应当类似如下内容,
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.contentView.backgroundColor = UIColor.cyan
return cell
}现在运行项目查看效果。

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP