4

My app uses a Navigation controller as the initial View Controller. Please see the screenshot attached

Main

In the first view controller, embedded in the navigation controller, I use the view did load method to set the navigation bar style as follows:

navigationController?.navigationBar.overrideUserInterfaceStyle = .dark
navigationController?.navigationBar.barStyle = .black
let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance 

The above 2 lines of codes, combined with the setting: View controller-based status bar appearance set to YES in the Info.plist allows me to successfully customize my status bar color as well as changing bar color when the user clicks on a specific button. Meaning that when the user clicks on a button on the same view controller, I can successfully change the status bar color settings to:

navigationController?.navigationBar.overrideUserInterfaceStyle = .light
navigationController?.navigationBar.barStyle = .default

Everything works as expected except when launching the app for the first time. When I kill the app and start it, the status bar color will be default instead of black. I have no idea why, it only happens when launching the app for the first time. Please see GIFs attached for example.

  • When starting the app, the status bar has a default style
  • When navigating away from the app, then back to it, the status bar has the correct style: .black

Im only facing this issue on the first screen of the app, the rest works just has expected. Wondering if anyone has an idea of whats going on here... Thanks in advance for your time!

Demo GIF

  • This might be helpfull : https://stackoverflow.com/a/68600926/14733292 – Raja Kishan Oct 26 '21 at 05:12
  • thank you @RajaKishan but the article you posted, only works for UIViewControllers. In my example (UINavigationControlle) overriding the preferredStatusBarStyle property wont work. See here: https://stackoverflow.com/questions/58125973/how-to-set-style-of-the-statusbar-embedded-in-a-navigation-controller-on-ios13 – Clément Besson Oct 26 '21 at 05:18
  • 1
    @ClémentBesson Overriding of preferredStatusBarStyle property in custom subclass of UINavigationController working fine in iOS 15. Why you use exactly navigationBar.overrideUserInterfaceStyle? – Dmytro Yashchenko Oct 26 '21 at 15:38
  • @ClémentBesson Its better to control status bar style directly thought preferredStatusBarStyle. In code snippets you provided there is no usage of this property... – Dmytro Yashchenko Oct 26 '21 at 15:57
  • @DmytroYashchenko I'm really grateful of your help here. Indeed I created my own subclass of the UINavigationController In my subclass, I overrode the following: override var preferredStatusBarStyle: UIStatusBarStyle { return myCustomTest ? .darkContent : .lightContent } Now its working like a charm, thanks a ton for your help! – Clément Besson Oct 27 '21 at 05:23
  • @DmytroYashchenko - you mention "Overriding of preferredStatusBarStyle property in custom subclass of UINavigationController working fine in iOS 15." Yes, this is working for me as well.However, this doesn't seem to work in case of navigation controllers in moreNavigationController. Any idea how to set the same? – Hasaa2 Khidala Jan 06 '22 at 23:49

0 Answers0