iOS 13 status bar style

Micky picture Micky · Aug 22, 2019 · Viewed 14.6k times · Source

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?

Answer

bezoadam picture bezoadam · Nov 15, 2019

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