I tried many ways to set the status bar style (default or lightcontent) but can\'t get it to work on a per view controller basis. I can set the status bar style for the
In the ViewController that you want to change the status bar's color
- (void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
- (void) viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Swift extension for this because I always forget how this works
extension UIViewController {
// utility to set the status bar appearance
// Note: Make sure "View controller-based status bar appearance" is set to NO in your target settings or this won't work
func setStatusBarForDarkBackground(dark: Bool) {
UIApplication.sharedApplication().statusBarStyle = dark ? .LightContent : .Default
setNeedsStatusBarAppearanceUpdate()
}
}
EDIT: This solution is deprecated on iOS 9. Please choose one of the other answers.
With UIViewControllerBasedStatusBarAppearance
set to NO, I was able to set the style to white text by using:
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTranslucent;
This is because the text color on this style was white on iOS 6 and below.
UPDATE: According to @jowie you can try that on iOS8:
[UIApplication sharedApplication].statusBarStyle = UIBarStyleBlack;
On viewDidLoad method, put this:
Objective C
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[self setNeedsStatusBarAppearanceUpdate];
Swift
UIApplication.shared.statusBarStyle = .lightContent
self.setNeedsStatusBarAppearanceUpdate()