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.redcell.selectedBackgroundView = bgColorView
swift 4 correction:
cell.selectionStyle = UITableViewCellSelectionStyle.gray
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 }() }}