I followed this thread to override -preferredStatusBarStyle
, but it isn't called.
Are there any options that I can change to enable it? (I'm using XIBs in my project.)
I had the same problem, and figured out it was happening because I wasn't setting the root view controller in my application window.
The UIViewController
in which I had implemented the preferredStatusBarStyle
was used in a UITabBarController
, which controlled the appearance of the views on the screen.
When I set the root view controller to point to this UITabBarController
, the status bar changes started to work correctly, as expected (and the preferredStatusBarStyle
method was getting called).
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
... // other view controller loading/setup code
self.window.rootViewController = rootTabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Alternatively, you can call one of the following methods, as appropriate, in each of your view controllers, depending on its background color, instead of having to use setNeedsStatusBarAppearanceUpdate
:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
or
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
Note that you'll also need to set UIViewControllerBasedStatusBarAppearance
to NO
in the plist file if you use this method.