2
votes

I want to change status bar style when presenting a view controller, and change it back when returning from it, this is my code:

In presented:

override func viewWillAppear(_ animated: Bool) {
    UIApplication.shared.statusBarStyle = .lightContent
}

In presenting:

override func viewWillAppear(_ animated: Bool) {
    UIApplication.shared.statusBarStyle = .default
}

My info.plist:

  • View controller-based status bar appearance = NO
  • Status bar style = default

The animation seemed quite intrusive, am I able to animate the change?

1
@aircraft that solved my problem, you can add a swift version here to let everyone see.Bright
thanks your advice, and I will do that after some hours. Busy now.aircraft

1 Answers

-1
votes

At First you do this: Open your info.plist and insert a new key named "View controller-based status bar appearance" to NO

and change the statusBar colour in whatever viewController.

Like this : UIApplication.sharedApplication().statusBarStyle = .LightContent

If you want to change colour on changing viewController put like this:

override func viewWillDisappear(animated: Bool)

{ super.viewWillDisappear(animated)

UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default

//this will change the colour when a particular viewController disappear.

}