I have been using
UIApplication.sharedApplication().setStatusBarStyle()
In my appDelegate and it has worked fine, but since iOS 9, this method
Swift 5, iOS 13.5+
I'm gonna make a recap that I hope it's gonna be helpful.
#1: General solution without using preferredStatusBarStyle
To answer the question, if we don't want to care about exceptions screens and not use the preferredStatusBarStyle
property from view controllers as Apple recommends, I think that indeed setting the UIViewControllerBasedStatusBarAppearance
to false
and changing the Status Bar Style
under General settings -> Deployment info
to light, as @Rick already recommended, is the way to go.
#2: Using preferredStatusBarStyle
For my case, I wanted to be able to have the UIStatusBarStyle.lightContent
as default, but with some screens having the UIStatusBarStyle.default
; and in these kind of cases, the solution #1 isn't possible.
Since also having a general extension to UIViewController
that allows to change the default value isn't obviously possible for this property, the only and best way to proceed in these cases if we don't want to use deprecated methods, is via inheritance.
So, a possibility is to have a general BaseViewController
(and also the BaseNavigationController
if you use one) that you controller inherits from, that sets the preferredStatusBarStyle
to .lightContent
.
With this approach, now you can simply set the style to default
where needed, while maintaining the lightContent
as default.