I am trying to change the appearance of a custom selected TableViewCell using Swift.
Do I need to do it via the designer or programmatically?
I tried the fol
Update for Swift 3
This answer is based on Cao Yong answer, and it is intended as an update for Swift 3
For Swift 3, use the following code in your cellForRowAt indexPath method set:
cell.selectionStyle = .none
Then, set it in didHighlightRowAtIndexPath
func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
cell!.contentView.backgroundColor = .red
}
func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
cell!.contentView.backgroundColor = .clear
}