Change the style of the status bar using animation

Since it’s UIApplication.shared.setStatusBarStyle(.default, animated: true)deprecated from iOS9, is it possible to change the style of the status bar with animation on push? I can not find descriptions in the docs.

+5
source share
3 answers

Now this is a variable that you must override:

override var preferredStatusBarStyle: UIStatusBarStyle
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation

Depending on when you update the status bar, you may also need to call setNeedsStatusBarAppearanceUpdate()

+10
source

If you want to set the status bar style, then set the application level UIViewControllerBasedStatusBarAppearanceto NOin your .plistfile.

, , :

  • UIViewControllerBasedStatusBarAppearance YES .plist, UIViewController.
  • addDidLoad add - setNeedsStatusBarAppearanceUpdate

  • StatusBarStyle .

-

override func viewDidLoad() {
    super.viewDidLoad()
    self.setNeedsStatusBarAppearanceUpdate()
}

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

.plist . enter image description here

+3

, .lightContent .default, , , - .

UIView.animate(withDuration: 0.2) { [weak self] in
        self?.setNeedsStatusBarAppearanceUpdate()
}

, , .

override var preferredStatusBarStyle: UIStatusBarStyle {
    return lightStatusBar ? .lightContent : .default
     // return .lightContent
}

, , .

0

Source: https://habr.com/ru/post/1670770/


All Articles