Remove the cell highlight color of UITableView

IosObjective CUitableview

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

In Swift:

cell.selectionStyle = UITableViewCell.SelectionStyle.none

or simply:

cell.selectionStyle = .none

Solution 2 - Ios

In the Storyboard or XIB Attributes Inspector, set Selection to None.


Selection: None

Solution 3 - Ios

Swift 3.0

cell.selectionStyle = .none

Solution 4 - Ios

// Swift 2.0

cell.selectionStyle = UITableViewCellSelectionStyle.None

Solution 5 - Ios

Objective-C:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

// or 

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

Swift 3+:

cell.selectionStyle = UITableViewCellSelectionStyle.none;

// or

cell.selectionStyle = .none

Swift 2:

cell.selectionStyle = UITableViewCellSelectionStyle.None

If you want to change it just using Interface Builder Storyboard/Xib, 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

Solution 6 - Ios

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

Solution 7 - Ios

Do it in the cell:

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

    ...
}

It's that easy.

Solution 8 - Ios

Try this for swift

cell?.selectionStyle = UITableViewCellSelectionStyle.None

Solution 9 - Ios

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.

Solution 10 - Ios

Swift 5.4 , just put the selectionStyle = .none

Example:

class TableViewCell: UITableViewCell {

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

}

Solution 11 - Ios

Swift 5:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnehaView Question on Stackoverflow
Solution 1 - IosVladimirView Answer on Stackoverflow
Solution 2 - IosMichaelView Answer on Stackoverflow
Solution 3 - IosRashwan LView Answer on Stackoverflow
Solution 4 - IosJoey WongView Answer on Stackoverflow
Solution 5 - IosFrantiesco MasuttiView Answer on Stackoverflow
Solution 6 - IosjoeView Answer on Stackoverflow
Solution 7 - IosFattieView Answer on Stackoverflow
Solution 8 - IosJugal K BalaraView Answer on Stackoverflow
Solution 9 - IosanrView Answer on Stackoverflow
Solution 10 - IoszeytinView Answer on Stackoverflow
Solution 11 - IosZgpeaceView Answer on Stackoverflow