我有一个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
设置颜色