如果将多选设置为真,颜色将更改为您为触摸的每个单元格指定的颜色。
但我想要的是将多选设置为 true 并仅将触摸单元格的颜色更改为白色。
这有可能吗?
这是我正在申请的来源。
class CustomCell: UITableViewCell {
@IBOutlet weak var btnCheck: UIButton!
override func layoutSubviews() {
super.layoutSubviews()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if selected {
contentView.backgroundColor = UIColor.blue
btnCheck.isSelected = true
self.isUserInteractionEnabled = false
} else {
contentView.backgroundColor = UIColor.white
btnCheck.isSelected = false
}
}
最佳答案
您可以使用以下代码执行此操作: 对我有用
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let cell : KichenListTableViewCell = tableView.cellForRow(at: indexPath) as? KichenListTableViewCell else {
return
}
cell.backgroundColor = UIColor.red
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
guard let cell : KichenListTableViewCell = tableView.cellForRow(at: indexPath) as? KichenListTableViewCell else {
return
}
cell.backgroundColor = UIColor.white
}
希望对你有帮助,谢谢
关于ios - swift - 在 UITableVIew 中将多选设置为 true 时如何设置选择颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51418306/