disable the uitableview highlighting but allow the selection of individual cells

when you tap on a cell the row gets selected and highlighted.Now what i want to do is disable the highlighting but allow the selection.Is there a way around it.There is question that answers this but it disables both the selection and highlighting.


Solution 1:

You can just set the cell's selection style to "None" from Storyboard:

See here

Or from code:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

For Swift 3:

cell.selectionStyle = UITableViewCellSelectionStyle.none

For Swift 4 & above:

cell.selectionStyle = .none

Solution 2:

Change UITableViewCell's selectedBackgroundView color to transparent.

    let clearView = UIView()
    clearView.backgroundColor = UIColor.clearColor() // Whatever color you like
    UITableViewCell.appearance().selectedBackgroundView = clearView

or to set for a specific cell:

cell.backgroundView = clearView