134
votes

I want to remove the default blue color of uitableview cell selection. I don't want any selection color there. I have not created a custom cell class. I'm customizing the cell by adding labels and buttons over it. I tried doing:

cell.selectioncolor = [UIColor clearcolor];

but it says that this method is deprecated.

11

11 Answers

371
votes
cell.selectionStyle = UITableViewCellSelectionStyleNone;

in Swift 4 updated

cell.selectionStyle = UITableViewCell.SelectionStyle.none

Or

cell.selectionStyle = .none
66
votes

Select this in Storyboard or XIB


enter image description here

13
votes
// Swift 2.0

cell.selectionStyle = UITableViewCellSelectionStyle.None
12
votes

Swift 3.0

cell.selectionStyle = .none
8
votes

Objective-C:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

or

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

Swift 4:

self.selectionStyle = UITableViewCellSelectionStyle.none;

Swift 3:

cell.selectionStyle = .none

Swift 2:

cell.selectionStyle = UITableViewCellSelectionStyle.None

If you want to change it just using Storyboard/Xib, just select the Cell that you want to remove the "Selection Style Effect" and define it as "None". It'll work like magic as well :D

Storyboard / Xib

7
votes

Setting the TableView Selection style to .none was affecting the responsiveness and performance of the tableview in my app (didSelectRowAt indexPath taps were getting delayed). My solution to this problem was to hide the selected background view on awakeFromNib() when the cell is first created:

selectedBackgroundView?.isHidden = true

4
votes

Try this for swift

cell?.selectionStyle = UITableViewCellSelectionStyle.None
4
votes

Do it in the cell:

class YourCell:  UITableViewCell {
    
    override func didMoveToSuperview() {
        selectionStyle = .none
    }

    ...
}

It's that easy.

2
votes

right answer should be:

cell.selectedBackgroundView?.backgroundColor = <choose your color>

The selection type is a different property that when set to .none produces what you want PLUS other unwanted side-effects.

If you do not want the cell to be highlighted, then make its background view's color the same as when it is not highlighted.

1
votes

Swift 5.4 , just put the selectionStyle = .none

Example:

class TableViewCell: UITableViewCell {

 override func awakeFromNib() {
    super.awakeFromNib()
    
    selectionStyle = .none 

}
0
votes

swift 5

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        cell.selectionStyle = .none

        return cell
    }