- Set "View controller-based status bar appearance” to NO in your info.list file;
Insert
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
to -application:didFinishLaunchingWithOptions:
of the AppDelegate.m.
Note: UIStatusBarStyleDefault
is the default value for the status bar style, it'll show black content instead. Both UIStatusBarStyleBlackTranslucent
& UIStatusBarStyleBlackOpaque
are deprecated in iOS 7.0.
UPDATE for iOS 9:
As @ZakariaDarwish mentioned, the method -setStatusBarStyle
is deprecated in iOS 9. (Note: The original question was asked for iOS 7 long time ago, and I don't support it now, the new solution below works for me under iOS 9, hence update here.)
So, the only way left (at least for now) is to implement -preferredStatusBarStyle
in your view controller (remember to set "View controller-based status bar appearance" back to YES).
You can invoke UIViewController's instance method -setNeedsStatusBarAppearanceUpdate
once value changed in -preferredStatusBarStyle
or -prefersStatusBarHidden
.
There're also two methods -childViewControllerForStatusBarStyle
& -childViewControllerForStatusBarHidden
to return the preferred style from child view controller as you want.
e.g., if you used below methods
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
to switch status bar style before, you can use code sample below
- (void)shouldChangeStatusBarStyleToLightContent:(BOOL)toLightContent
animated:(BOOL)animated
{
_shouldChangeStatusBarStyleToLightContent = toLightContent;
if (animated) {
[UIView animateWithDuration:.3f animations:^{ [self setNeedsStatusBarAppearanceUpdate]; }];
} else {
[self setNeedsStatusBarAppearanceUpdate];
}
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return (_shouldChangeStatusBarStyleToLightContent ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault);
}
for this updated solution now.