I want to change the status bar style on a per-ViewController level on iOS 13. So far I didn't have any luck.
I define UIUserInterfaceStyle
as Light
in info.plist (as I do not want to support dark mode) and set UIViewControllerBasedStatusBarAppearance
to true
. preferredStatusBarStyle
is called on my ViewController but completely ignored. The UIUserInterfaceStyle
seems to always override the VC preferences.
How do I get per-ViewController status bar style working on iOS 13? Or is it not supported any more?
You can change the status bar colour just with a single line of code. Just updated the markdown for iOS 13 and below.
A status bar appears along the upper edge of the screen and displays information about the device's current state, like the time, cellular carrier, and battery level.
Open your info. plist and set UIViewControllerBasedStatusBarAppearance to false . In the first function in AppDelegate. swift , which contains didFinishLaunchingWithOptions , set the color you want.
iOS 13.2, Swift 5.1
For me nothing worked from solutions mentioned before. After 5 hours I ended up on modalPresentationCapturesStatusBarAppearance flag .
destinationNavigationController.modalPresentationCapturesStatusBarAppearance = true
sourceViewController.present(destinationNavigationController, animated: animated, completion: nil)
After this preferredStatusBarStyle
was called in presented VC.
override var preferredStatusBarStyle: UIStatusBarStyle {
if #available(iOS 13.0, *) {
if traitCollection.userInterfaceStyle == .light {
return .darkContent
} else {
return .lightContent
}
} else {
return .lightContent
}
}
I had the same issue on iOS13 while it was fine on iOS12 for my app. I have a TabBarController which holds 3 NavigationBarControllers, and I present TabBarController from a previous ViewController. I fixed it by setting .modalPresentationStyle to .fullScreen when presenting:
tabbarController.modalPresentationStyle = .fullScreen
Maybe it will help you somehow...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With