To dynamically update UIStatusBarStyle on view controllers use this method
this will also remove deprecated warning
'setStatusBarStyle:' is deprecated: first deprecated in iOS 9.0 - Use -[UIViewController preferredStatusBarStyle]
for calling
[[UIApplication sharedApplication] setStatusBarStyle:style];
Let's Get Started
Objective - C
define UtilityFunction
+(void)setStatusBarStyle:(UIStatusBarStyle )style {
[[NSUserDefaults standardUserDefaults] setInteger:style forKey:@"UIStatusBarStyle"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
over-ride this method in your BaseViewController
- (UIStatusBarStyle)preferredStatusBarStyle {
UIStatusBarStyle style = [[NSUserDefaults standardUserDefaults] integerForKey:@"UIStatusBarStyle"];
return style;
}
set UIStatusBarStyle value for the AnyViewController using a UtilityFunction like below:
[UtilityFunctions setStatusBarStyle:UIStatusBarStyleDefault];
// call below code for preferred style
[self preferredStatusBarStyle];
Swift 4.0
define UtilityFunction
class func setPreferedStyle(style:UIStatusBarStyle)->Void {
UserDefaults.standard.set(style, forKey: "UIStatusBarStyle")
UserDefaults.standard.synchronize()
}
over-ride this method in your BaseViewController
override var preferredStatusBarStyle: UIStatusBarStyle {
if let style: UIStatusBarStyle = UIStatusBarStyle(rawValue:UserDefaults.standard.integer(forKey: "UIStatusBarStyle")) {
return style
}
return UIStatusBarStyle.lightContent
}
set UIStatusBarStyle value for the AnyViewController using a UtilityFunction like below:
Utility.setPreferedStyle(style: .lightContent)
// call below code for preferred style
preferredStatusBarStyle()