Changing background color of selected cell?

后端 未结 30 2992
太阳男子
太阳男子 2020-11-29 00:22

Does anyone know how to change the background color of a cell using UITableViewCell, for each selected cell? I created this UITableViewCell inside the code for TableView.

30条回答
  •  余生分开走
    2020-11-29 01:04

    in Swift 3, converted from illuminates answer.

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        if(selected) {
            self.selectionStyle = .none
            self.backgroundColor = UIColor.green
        } else {
            self.backgroundColor = UIColor.blue
        }
    }
    

    (however the view only changes once the selection is confirmed by releasing your finger)

提交回复
热议问题