UITableView
cell highlight
iOS development
app design
programming tips

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.

Browse interview questions

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:

swift
1import UIKit
2
3final class ExampleViewController: UITableViewController {
4    override func tableView(
5        _ tableView: UITableView,
6        cellForRowAt indexPath: IndexPath
7    ) -> UITableViewCell {
8        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
9            ?? UITableViewCell(style: .default, reuseIdentifier: "Cell")
10
11        cell.textLabel?.text = "Row \(indexPath.row)"
12        cell.selectionStyle = .none
13        return cell
14    }
15}

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:

swift
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    print("Tapped row \(indexPath.row)")
}

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:

swift
tableView.allowsSelection = false

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:

swift
let selectedView = UIView()
selectedView.backgroundColor = .clear
cell.selectedBackgroundView = selectedView

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:

swift
1final class PlainCell: UITableViewCell {
2    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
3        super.init(style: style, reuseIdentifier: reuseIdentifier)
4        selectionStyle = .none
5    }
6
7    required init?(coder: NSCoder) {
8        super.init(coder: coder)
9        selectionStyle = .none
10    }
11}

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 = .none to remove the default highlight color while keeping tap handling.
  • Use storyboard Selection = None for the same effect in Interface Builder.
  • Use tableView.allowsSelection = false only when rows should not be interactive at all.
  • For custom visuals, set a selectedBackgroundView instead 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
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.