Remove the cell highlight color of UITableView
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If you want a UITableViewCell to stop showing the default gray highlight when tapped, the usual fix is to change its selection style to .none. The important detail is that highlight and selection are part of UIKit’s touch feedback system, so removing them should be an intentional design choice rather than a random visual tweak.
Disable the Default Selection Style
For most table views, this is the direct answer:
With selectionStyle = .none, the cell can still receive taps, but UIKit will not draw the normal highlighted selection background.
Storyboard Version
If the cell comes from a storyboard, you can set the same behavior without code:
- select the table-view cell
- open the Attributes Inspector
- change Selection from Default to None
This is the same underlying setting, just configured visually.
Keep Tap Behavior Without Highlight
Developers sometimes think removing the highlight also disables interaction. It does not. If you still implement tableView(_:didSelectRowAt:), the tap callback still fires:
That means you can remove the visual highlight and keep custom navigation or action behavior.
Disable All Selection Only If That Is the Goal
If the table should not allow row selection at all, that is a separate choice:
This is stronger than changing the cell’s selection style. Use it only when the rows should behave like static content rather than tappable items.
Custom Selected Backgrounds
Sometimes the real requirement is not “remove highlight entirely,” but “replace the default color with something else.” In that case, use selectedBackgroundView instead of turning selection off:
This gives you full control over what UIKit shows during selection.
Watch Reuse Behavior
Because table-view cells are reused, the selection configuration belongs in cellForRowAt or inside a custom cell subclass setup method. If you set it only once during initial creation and assume every reused cell inherits the same styling path, you can end up with inconsistent behavior.
For custom cells, putting the setup into the class itself can be cleaner:
Common Pitfalls
The most common mistake is confusing “no highlight” with “no tap handling.” Setting selectionStyle = .none removes the visual effect, but the cell can still be selected logically and still trigger delegate callbacks.
Another pitfall is disabling selection globally with allowsSelection = false when the rows still need to respond to taps. That solves the visual problem by changing interaction semantics too, which is often not what the screen needs.
It is also easy to forget cell reuse. If highlight-related properties are not set consistently during reuse, some rows may behave differently from others.
Finally, removing the highlight without adding any alternative cue can make a table feel unresponsive. If the row still performs an action, consider another visual signal or quick animation so the user gets feedback.
Summary
- Use
cell.selectionStyle = .noneto remove the default highlight color while keeping tap handling. - Use storyboard Selection = None for the same effect in Interface Builder.
- Use
tableView.allowsSelection = falseonly when rows should not be interactive at all. - For custom visuals, set a
selectedBackgroundViewinstead of disabling selection. - Remember that touch feedback is part of usability, so remove it only with an intentional replacement or clear interaction model.
Related reading
- Removing an activity from the history stack
- Removing duplicate elements from an array in Swift
- Removing object from array in Swift 3
- Removing the title text of an iOS UIBarButtonItem
- Removing viewcontrollers from navigation stack
- Renew Provisioning Profile
- Renew Push certificate and keep current App Store App working
- Replace Fragment inside a ViewPager
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.