当我点击或按住 UITableView 中的某个单元格时,该单元格的颜色默认变为灰色。我想要它是其他颜色。我在故事板和堆栈溢出中到处查看,但找不到它。我们该怎么做。
尝试像这样改变它,例如它将是红色的:
let bgColorView = UIView()
bgColorView.backgroundColor = UIColor.redColor()
cell.selectedBackgroundView = bgColorView
这是基于@evgeny-karkan 答案的扩展
extension UITableViewCell {
func changePressDownColor(to Color: UIColor){
let bgColorView = UIView()
bgColorView.backgroundColor = Color
self.selectedBackgroundView = bgColorView
}
}
用途:
cell.changePressDownColor(to: .red)