[英]Swift4: How to change UITableView cell color
我有一個 UITable 視圖,您可以在其中按按鈕添加項目。 我希望它的單元格清晰,我已經將其背景設為半透明,但是一旦您單擊允許您保存其中項目的按鈕,您保存的第一個背景就會變成白色。 然后,如果您在其他時間按下按鈕,除最后創建的單元格之外的所有單元格都將變為半透明,但一個仍為白色。 這是我的代碼,我怎樣才能讓它完全清楚?
extension ViewController : UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return number.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let textCell = tableView.dequeueReusableCell(withIdentifier: "WordCell", for: indexPath)
textCell.textLabel?.text = "\(indexPath.row + 1) \(number[indexPath.row])"
let semitransparentBlack = UIColor(rgb: 0x000000).withAlphaComponent(0.3)
textCell.layer.backgroundColor = semitransparentBlack.cgColor
textCell.textLabel?.layer.backgroundColor = semitransparentBlack.cgColor
textCell.textLabel?.textColor = UIColor.white
return textCell
}
}
您可以使用textCell.backgroundColor = semitransparentBlack
設置顏色
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.