Change global tint color - iOS7/iOS8
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.
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]];
[[UIView appearance] setTintColor:[UIColor greenColor]];
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.
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;
}
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()