How To Set A Custom UITableViewCell Selection Style Color

The storyboard only gives three options for the Selection color of a UITableViewCell:

Screen Shot 2013-07-09 at 6.56.42 AM

However, for my ShopLater app, I wanted the selected cell to be pink! Why only blue or gray?!!! I was surprised when I found the answer on how to do it, but it makes sense. Basically the the selection color of a UITableViewCell is actually a background color on a subview of the cell.

So, to change the selection color, simply assign a different selection view to the selected background view of your cell in your code!

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:sMenuStoreCell 

   // configure your cell here

    // this is where you set your color view
    UIView *customColorView = [[UIView alloc] init];
    customColorView.backgroundColor = [UIColor colorWithRed:180/255.0 
    cell.selectedBackgroundView =  customColorView;

    return cell;

Here is what the ShopLater selected cell looks like with this code in place:


This is really cool. Just think of the possibilities. You could actually configure a fun background image instead of just a color when the user selects a cell! You can also have different selection backgrounds for each cell. I just hope Apple would approve the fun 🙂

Enjoy the article? Join over 20,000+ Swift developers and enthusiasts who get my weekly updates.

  • jjthetrader

    Thank you so much for this!

    In swift I did this:
    . var myCustomSelectionColorView = UIView()
    myCustomSelectionColorView.backgroundColor = UIColor.greenColor()
    cell.selectedBackgroundView = myCustomSelectionColorView

    • MizAkita

      thanks for this!

  • RemyDCF

    Thank You

  • thanks for this. The advantage of having an experience working with Objective-C is really helpful, I started my journey in iOS using that language, and now I’m using Swift in my new company. 😀 Just saying that I can easily convert this to Swift. haha.


  • Philippe Badizé

    Many thanks again, Natasha !

    In case you want a blurred background for the cell (and not a color), you might want to use for Swift 3 :

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let product = products[indexPath.row]
    let cell = tableView.dequeueReusableCell(withIdentifier: ViewController.tableViewCellIdentifier, for: indexPath)

    configureCell(cell as! WelcomeTableViewCell, forProduct: product)

    //HERE : Let’s add the blur effect to the selected cell
    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
    let blurEffectView = UIVisualEffectView(effect: blurEffect)
    cell.selectedBackgroundView = blurEffectView

    return cell


  • JEK

    Thank you!!! Thank you!!! I was searching for so long to find this solution!