Is there a way how to set the default status bar style while keeping the UIViewControllerBasedStatusBarAppearance
Here is the problem, I'm dealing with:
Nearly the whole app needs to be using
UIStatusBarStyle.LightContent
UIViewControllerBasedStatusBarAppearance
Info.plist
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
.LightContent
UIViewControllerBasedStatusBarAppearance
UIApplication.sharedApplication().setStatusBarStyle()
The easiest and cleanest way who to achieve that is to add the following line in AppDelegate
's application:willFinishLaunchingWithOptions
method:
UINavigationBar.appearance().barStyle = .Black
This will make .LightContent
as the default status bar style thorough the app as long as your app uses UINavigationController
.
Don't forget to keep the following setting in app's Info.plist
if want to use .LightContent
status bar style during launch for splash screen:
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
My current setup, which is very similar to many other apps, uses UITabBarController
as the top most controller with UINavigationController
stack for each tab.
UINavigationController
takes care of the status bar style (as it should) and do not call preferredStatusBarStyle()
on its child view controllers. Therefore, implementing the subclassing solution proposed by par does not work in my case.
Further subclassing the custom subclass of UINavigationController
I'm using would not be a clean solution either.
Now, since the app has UIViewControllerBasedStatusBarAppearance
enabled and correct status bar style everywhere in the app itself, SFSafariViewController
and share extension like Messages, Mail, etc use the correct (.Default
) status bar style too.
The only exception where the correct status bar style is not used is the Facebook Messenger's share extension mentioned in the question. However, it seems to be a bug in the extension itself as all apps I have tried that use .LightContent
status bar style (like Twitter, for example) have the same issue - presented FB Messenger share extension from the app has a status bar with white color text.