如何在 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 }
現在執行專案檢視效果。
廣告