iOS: How to Change UITableViewCell’s Selection Color App Wide

As part of your app branding, you might want to use a different selection color for all your tableViewCells!¬†For example, let’s say I want the table view cells in my demo Seinfeld Quotes app to be yellow:

SelectionColor

Of course you can set your cell’s selectedBackgroundView easily for every cell, but there is a less known app-wide way to configure your cell’s appearance.

Just add the following simple code in your AppDelegate:

class AppDelegate: UIResponder, UIApplicationDelegate {
                            
    //... truncated

    func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
        
        // set up your background color view
        let colorView = UIView()
        colorView.backgroundColor = UIColor.yellowColor()

        // use UITableViewCell.appearance() to configure 
        // the default appearance of all UITableViewCells in your app
        UITableViewCell.appearance().selectedBackgroundView = colorView

        return true
    }

    //... truncated
}

Just like you can set the tableViewCell’s selectedBackgroundView, you can also configure the default cell’s textLabel’s font

UITableViewCell.appearance().textLabel?.font = UIFont.boldSystemFontOfSize(12) 

or color

UITableViewCell.appearance().textLabel?.textColor = UIColor.blueColor()

and more!

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

  • Mike Abdullah

    ingenious!

  • Ome_Twi

    Well, what is I need several tables in my app with different selection styles?