0
votes

I'm trying to change my the color of the status bar on my application. As default, the color right now is white (I never set it up) and my color of the background is also white, so I can't really see the status bar. I tried changing it in my ViewController by adding this property:

private var style: UIStatusBarStyle = .default

this is my preferredStatusBarStyle:

override var preferredStatusBarStyle: UIStatusBarStyle {
    return self.style
}

and on viewDidAppear I tried this:

override func viewDidAppear(_ animated: Bool) {
    style = .default
    setNeedsStatusBarAppearanceUpdate()
}

This is an answer I saw here on Stackoverflow, but it just won't work for me. I tried changing the navigationBar barStyle also, also didn't work.

I'm using a TabBarController embedded in NavigationController, tried to change both navBarColor / preferredStatusBarStyle, also didn't work.

Info.plist Picture: enter image description here

2
Is this solving your issue: stackoverflow.com/a/61394686/2781088 - Mohit Kumar
@MohitKumar Thanks, I already tried changing the options there, but it didn't solve the issue. - John Doah
Can you add a screenshot of your info.plist - Mohit Kumar
@MohitKumar I added the relevant section of the info.plist. - John Doah
Please check the answer below, if this solves your issue. Sorry for late reply. - Mohit Kumar

2 Answers

0
votes

Do

    private(set) var isDark: Bool = false {
        didSet {
            setNeedsStatusBarAppearanceUpdate()
        }
    }

    override var preferredStatusBarStyle: UIStatusBarStyle {
        if #available(iOS 13.0, *) {
            return isDark ? .darkContent : .lightContent
        } else {
            return isDark ? .default : .lightContent
        }
    }

    final func changeStatusBarStyle(isDark: Bool) {
        self.isDark = isDark
        navigationController?.navigationBar.barStyle = isDark ? .default : .black
    }

0
votes

Step 1: Set your status bar color here:

enter image description here

Step 2: Add this entry to .plist

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

Now your status bar color will not be viewController based and whatever color you will set in Step 1, will reflect in the full app.

Please let me know if this solves your issue.