【发布时间】:2019-08-03 01:40:00
【问题描述】:
我有一个 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吗? -
完美,谢谢,我不知道我可以在没有图层的情况下做到这一点,我的意思是,当我尝试其他时候我收到错误消息...谢谢它看起来很棒!
-
如果你也可以试试
textCell.contentView.backgroundColor = semitransparentBlack
标签: swift uitableview tableview background-color