1

I have 2 StoryBoard in my project and all ViewController in my 1st storyBoard are of .lightContent statusBarStyle and all ViewController in my 2nd storyBoard are of .default statusBarStyle.

For that i have done below steps.

1.View controller-based status bar appearance is true

2 Already use below code.

extension UINavigationController {
    open override var preferredStatusBarStyle: UIStatusBarStyle {
       return topViewController?.preferredStatusBarStyle ?? .default
    }
}

When i set 2nd storyBoard ViewController as rootController from 1st storyBoard statusBar style changing but i am facing below issue.

When i set 1st storyBoard ViewController as rootController, statusBarStyle update after few seconds.

Not Proper

enter image description here

After Few Seconds

enter image description here

here is my demo link : https://www.dropbox.com/s/ijqg73zm1jxbokc/statusBarDemo.zip?dl=0

UPDATE

MY First ViewController Code

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
}

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .default
}

@IBAction func btnInitialControllerTapped(_ sender: Any) {
    let controller = UIStoryboard(name: "Initial", bundle: nil).instantiateViewController(withIdentifier: "InitialViewController") as! InitialViewController
    let navController = UINavigationController.init(rootViewController: controller)
    appDelegate.window?.rootViewController = navController
}

MY Second ViewController Code

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

@IBAction func btnControllerTapped(_ sender: Any) {
    let storyboard = UIStoryboard(name:"Main", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
    let navigationController = UINavigationController(rootViewController: vc)
    appDelegate.window?.rootViewController = navigationController
}

Please guide me what i'm missing or what i have implemented wrongly. Any help will be appreciated. Thanks

Kuldeep
  • 4,466
  • 8
  • 32
  • 59

1 Answers1

1

InitialViewController:

var status = true
override var preferredStatusBarStyle: UIStatusBarStyle {
    return status ? .lightContent : .default
}

@IBAction func btnControllerTapped(_ sender: Any) {
    self.status = false
    self.preferredStatusBarStyle
    self.setNeedsStatusBarAppearanceUpdate()
    let storyboard = UIStoryboard(name:"Main", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
    let navigationController = UINavigationController(rootViewController: vc)
    appDelegate.window?.rootViewController = navigationController
}

I found a solution like this. It works well but I don't know how useful it is.I just think it's better to change it without go on the other screen.

Kasım Özdemir
  • 5,414
  • 3
  • 18
  • 35
  • Thanks for your help. This works, but in my app this code will execute from all ViesController if token is expired so for this i have to put this code in every controller. is there any global solution for that? – Kuldeep Apr 30 '20 at 10:05
  • I didn't find any solutions for that – Kasım Özdemir Apr 30 '20 at 12:47
  • @Kuldeep its a separate question that how to run a code in all view controllers, and it also has its own solutions. If the above answer solves the problem asked in the question, then you should accept this answer and upvote it. Trust me it won't cost you anything ;) – S1LENT WARRIOR May 01 '20 at 10:05