Change global tint color - iOS7/iOS8

Ios7UicolorTintcolor

Ios7 Problem Overview


How can we change the global tint color on iOS7/iOS8 by code? I want to change multiple objects that use this property, but not change each one, that's why I want to use the global tint property.

Ios7 Solutions


Solution 1 - Ios7

Simply change the UIWindow 's tintColor in your application delegate, it's automatically passed as default to all its UIView descendants.

[self.window setTintColor:[UIColor greenColor]];

Solution 2 - Ios7

[[UIView appearance] setTintColor:[UIColor greenColor]];

Solution 3 - Ios7

There are two ways to change your global tint color. As many mentioned above you could change self.window.tintColor in -application:didFinishLaunchingWithOptions:.

More elegant way, in my opinion, is to set Global Tint in File Inspector in your Storyboard while nothing is selected. This way your -application:didFinishLaunchingWithOptions: is cleaner.

Global Tint in File Inspector

Solution 4 - Ios7

You can specify a tint color for the entire app by setting the window’s tint property. To do this, you could use code similar to the following:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.tintColor = [UIColor purpleColor];
    return YES;
}

Solution 5 - Ios7

Updated for Swift 2.2

You can do this from anywhere like this:

// Get app delegate
let sharedApp = UIApplication.sharedApplication()

// Set tint color
sharedApp.delegate?.window??.tintColor = UIColor.green()

Or if you're trying to do this from AppDelegate,

self.window?.tintColor = UIColor.green()

Solution 6 - Ios7

Updated for Swift 5

Write in the App Delegate :

self.window?.tintColor = UIColor.green

Solution 7 - Ios7

Following things DID NOT WORKED for me:

navigationItem.backBarButtonItem?.tintColor = Theme.light.healthKit.BACK_BUTTON_TITLE_COLOR

navigationItem.backBarButtonItem?.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : Theme.light.healthKit.BACK_BUTTON_TITLE_COLOR], for: .normal)

self.navigationController?.navigationBar.barStyle = UIBarStyle.black

navigationController?.navigationBar.barTintColor = Theme.light.healthKit.BACK_BUTTON_TITLE_COLOR

navigationController?.navigationBar.tintColor = Theme.light.healthKit.BACK_BUTTON_TITLE_COLOR

navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor : Theme.light.healthKit.BACK_BUTTON_TITLE_COLOR]

Following WORKED :

  1. SET THE GLOBAL TINT COLOR FROM STORYBOARD.

OR

  1. SET THE TINT COLOR OF THE WINDOW

FOR WHOLE APP:

let sharedApp = UIApplication.sharedApplication()
sharedApp.delegate?.window??.tintColor = UIColor.green()

FOR SPECIFIC CONTROLLER:

set tint color of window while initialization and set back the default tint color of the app while deinitialization.

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        let window = UIApplication.shared.windows.first
        window?.tintColor = Theme.light.healthKit.BACK_BUTTON_TITLE_COLOR
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        let window = UIApplication.shared.windows.first
        window?.tintColor = Theme.light.healthKit.BACK_BUTTON_TITLE_COLOR
    }

    deinit {
        let window = UIApplication.shared.windows.first
        window?.tintColor = Theme.light.App.DEFAULT_TINT_COLOR
    }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionelGeekalphaView Question on Stackoverflow
Solution 1 - Ios7VinzzzView Answer on Stackoverflow
Solution 2 - Ios7CarmenView Answer on Stackoverflow
Solution 3 - Ios7totocasterView Answer on Stackoverflow
Solution 4 - Ios7Gerardo Blanco GarcíaView Answer on Stackoverflow
Solution 5 - Ios7Tulio TroncosoView Answer on Stackoverflow
Solution 6 - Ios7Stanislas HeiliView Answer on Stackoverflow
Solution 7 - Ios7Shubham OjhaView Answer on Stackoverflow