Change Status Bar Color in Real Time

后端 未结 2 1495
清酒与你
清酒与你 2020-12-21 21:58

I am moving in a side menu view controller (ENSwiftSideMenu) with an animation. Since the side menu\'s background color is a pretty dark blue, I\'d like to have the status b

相关标签:
2条回答
  • 2020-12-21 22:30

    Updating status bar style directly is deprecated, and will not work when view controller-based status bar appearance is enabled.

    Instead, each controller has to provide its preferred status bar style, and the framework responsible for displaying each controller should implement childViewControllerForStatusBarStyle and provide the correct child controller for status bar appearance. Unfortunately, ENSwiftSideMenu does not support that, and thus you will have a hard time implementing this with view controller-based status bar appearance. You should open an issue with the original developer, but I suggest also switching to a better written framework.

    0 讨论(0)
  • 2020-12-21 22:55

    Try This Code:

    In your AppDelegate:

         var navigationBarAppearace = UINavigationBar.appearance()
         navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()] // If you want to change title colour
         UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default 
    

    //Update your plist with below code

         View controller-based status bar appearance = NO
    

    In your ViewController:

        override func viewDidLoad() {
        super.viewDidLoad()
    
         // UIApplication.sharedApplication().statusBarStyle = .LightContent
        navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
        navigationController?.navigationBar.shadowImage = UIImage()
        navigationController?.navigationBar.tintColor = UIColor.whiteColor()
        navigationController?.navigationBar.translucent = true
    }
    
    func sideMenuWillOpen() {
        print("sideMenuWillOpen")
    UIApplication.sharedApplication().statusBarStyle = .LightContent
    }
    
    func sideMenuWillClose() {
        print("sideMenuWillClose")
     UIApplication.sharedApplication().statusBarStyle = .Default 
    }
    

    Output from the above code.You can use some sort of UIAnimation to sync the effect..

    Let me know.If the code works for you...

    0 讨论(0)
提交回复
热议问题