How to programmatically change iOS app’s global tint colour, Navigation / Toolbar / Tab Bar’s tint (i.e. Text & Icon Colour) & bar tint colour (i.e. Background colour) using Swift Language while developing app in Xcode

Let’s get to the root of this topic,

 
Case: A case where you are developing your iOS app & you want to use your custom colour to colorise global tint colour for text & icon in your respective app & you also want to change tint & bar tint colour for Navigation Bar / Tab Bar / Tool Bar in your app.

 

Assumption: I assume you are well worse with iOS development in Xcode, You have embedded navigation controller to your app storyboard’s respective view controller & you have added tab bar view controller or dragged toolbar to your app’s view controller. I also assume you are using Swift as your programming language.

 
Solutions:

 

Note: You will have to copy following code in your iOS App’s AppDelegate.swift file’s ‘didFinishLaunchingWithOptions’ function while developing the same app in Xcode.

 
Here is how to change global tint color of iOS App

 

// change global tint color
self.window?.tintColor = UIColor.blackColor() /* Change tint color using Xcode default vales */
self.window?.tintColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0) /* Change tint color using custom RGB values copied from respective raster image editor like Photoshop or Pixelmator */

 
Here is how to change tint & background colour of Navigation Bar

 

// change tint color of navigation bar items
UINavigationBar.appearance().tintColor = UIColor.blackColor() /* Change tint color using Xcode default vales */
UINavigationBar.appearance().tintColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0) /* Change tint color using custom RGB values copied from respective raster image editor like Photoshop or Pixelmator */

// change tint color of navigation bar background
UINavigationBar.appearance().barTintColor = UIColor.grayColor() /* Change background color using Xcode default vales */
UINavigationBar.appearance().barTintColor = UIColor(red: 204/255, green: 204/255, blue: 204/255, alpha: 1.0) /* Change background color using custom RGB values copied from respective raster image editor like Photoshop or Pixelmator */

 
Here is how to change tint & background colour of Tool Bar

 

// change tint color of tool bar items
UIBarButtonItem.appearance().tintColor = UIColor.blackColor() /* Change tint color using Xcode default vales */
UIBarButtonItem.appearance().tintColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0) /* Change tint color using custom RGB values copied from respective raster image editor like Photoshop or Pixelmator */

// change tint color of tool bar background
UIToolbar.appearance().barTintColor = UIColor.grayColor() /* Change background color using Xcode default vales */
UIToolbar.appearance().barTintColor = UIColor(red: 204/255, green: 204/255, blue: 204/255, alpha: 1.0) /* Change background color using custom RGB values copied from respective raster image editor like Photoshop or Pixelmator */

 
Here is how to change tint & background colour of Tab Bar

 

// change tint color of tab bar items
UITabBar.appearance().tintColor = UIColor.blackColor() /* Change tint color using Xcode default vales */
UITabBar.appearance().tintColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0) /* Change tint color using custom RGB values copied from respective raster image editor like Photoshop or Pixelmator */

// change tint color of tab bar background
UITabBar.appearance().barTintColor = UIColor.grayColor() /* Change background color using Xcode default vales */
UITabBar.appearance().barTintColor = UIColor(red: 204/255, green: 204/255, blue: 204/255, alpha: 1.0) /* Change background color using custom RGB values copied from respective raster image editor like Photoshop or Pixelmator */

 

Note: Use respective Xcode default values or RGB values as per requirement, It is not required use both values at a time.

 
So your final ‘didFinishLaunchingWithOptions’ will look something like this:

 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        self.window?.tintColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0)
        UINavigationBar.appearance().barTintColor = UIColor(red: 204/255, green: 204/255, blue: 204/255, alpha: 1.0)
        UIToolbar.appearance().barTintColor = IColor(red: 204/255, green: 204/255, blue: 204/255, alpha: 1.0)
        UITabBar.appearance().barTintColor = IColor(red: 204/255, green: 204/255, blue: 204/255, alpha: 1.0)
        return true
    }

 
Hope it helps,

 
Thanks & Regards
Mandar Apte

Mandar Apte

This website contains a design articles blog by Mandar Apte. He writes and shares his iOS development, graphic, web, & animation film design experience through articles. Mandar is Mumbai based multi-disciplinary designer with expertise in UI, UX, Logo, Symbol, and Brand Identity design. He is an alumnus of Sir J. J. Institute of Applied Art, Mumbai. He currently runs his studio in the heart of the city of Mumbai.

One thought on “How to programmatically change iOS app’s global tint colour, Navigation / Toolbar / Tab Bar’s tint (i.e. Text & Icon Colour) & bar tint colour (i.e. Background colour) using Swift Language while developing app in Xcode

Leave a Reply

Your email address will not be published. Required fields are marked *