How to change selected color for table view cell?
You can do either one of this -
- Change the selectionStyle property of your cell.
For example: If you change it to UITableViewCellSelectionStyleGray, it will be gray.
cell.selectionStyle = UITableViewCellSelectionStyleGray;
Change the selectedBackgroundView property.
let bgColorView = UIView() bgColorView.backgroundColor = UIColor.red cell.selectedBackgroundView = bgColorView
swift 4 correction:
cell.selectionStyle = UITableViewCellSelectionStyle.gray
Maybe you need this:
cell.selectedBackgroundView
you can set the Selected Background view in awakeFromNib method
class MyCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
selectedBackgroundView = {
let view = UIView.init()
view.backgroundColor = .white
return view
}()
}
}