Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 13 status bar style

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?

like image 375
Micky Avatar asked Aug 22 '19 11:08

Micky


People also ask

Can we change status bar color in iOS?

You can change the status bar colour just with a single line of code. Just updated the markdown for iOS 13 and below.

What is the iOS status bar?

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.

How do I change the color of my status bar in Swift?

Open your info. plist and set UIViewControllerBasedStatusBarAppearance to false . In the first function in AppDelegate. swift , which contains didFinishLaunchingWithOptions , set the color you want.


Video Answer


2 Answers

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
    }
}
like image 168
bezoadam Avatar answered Oct 09 '22 12:10

bezoadam


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...

like image 3
Volodymyr Davydenko Avatar answered Oct 09 '22 12:10

Volodymyr Davydenko