I'm updating an iOS app for iOS 12 and ran into this warning.
I'm changing the status bar in the AppDelegate.swift file for my app. This can be found in the didFinishLaunchingWithOptions function
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
I'm getting a warning that says this:
Setter for 'statusBarStyle' was deprecated in iOS 9.0: Use -[UIViewController preferredStatusBarStyle]
I thought this would be an easy update, but I haven't found an update that has worked for me.
I tried setting this on the main VC:
// set the status bar color
override var preferredStatusBarStyle : UIStatusBarStyle {
return .lightContent
}
But it's not displaying in light mode.
When I try and type the override out myself, this is what I get for code hinting.
Going through the UIApplication documentation, it seems that there is no alternative symbol there for setting the status bar style. Instead, I would do what the warning instructs: Use -[UIViewController preferredStatusBarStyle]
.
You could set the status bar background color, but that doesn't seem to be what you're looking for.
Given the limitations, it seems that Apple wants us to have view controllers set the status bar style. I'm not sure why this is better from a design perspective, but there doesn't seem to be much legal stuff we can do about it.