Search code examples
iosswiftstatusbar

iOS StatusBar color change animation


I use the following code to change the StatusBar color in my ViewController:

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

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

And the parameter View controller-based status bar appearance in info.plist is set to NO

But the problem is that the StatusBar color changes from black to white without animation, and I want to make smooth transition between these states. Any ideas?

Xcode 10 Beta 5, iOS 12 Dev Beta 6


Solution

  • You can set following for one VC

     override var preferredStatusBarStyle: UIStatusBarStyle {
            return .lightContent
        }
    

    and then set the other as below

    override var preferredStatusBarStyle: UIStatusBarStyle {
            return UIStatusBarStyle.default
        }