How to change UIStatusBarStyle in iOS 7 in modal views with navigation bar?

后端 未结 9 2415
孤独总比滥情好
孤独总比滥情好 2020-12-31 11:32

The iOS 7 Transition Guide give a good hint how to change the UIStatusBarStyle dynamically in a UIViewController using

- (UIStatus         


        
9条回答
  •  执念已碎
    2020-12-31 12:05

    The key to making this work is that only the fullscreen view controller get's to dictate the style of the status bar.

    If you are using a navigation controller and want to control the status bar on a per view controller basis, you'll want to subclass UINavigationController and implement preferredStatusBarStyle such that it returns the topViewController's preference.

    Make sure you change the class reference in your storyboard scene fromUINavigationController to your subclass (e.g. MyNavigationController in the example below).

    (The following works for me. If your app is TabBar based, you'll want to do something similar by subclassing the UITabBarController but I haven't tried that out).

    @interface MyNavigationController : UINavigationController
    
    @end
    
    @implementation MyNavigationController
    
    - (UIStatusBarStyle)preferredStatusBarStyle
    {
        return self.topViewController.preferredStatusBarStyle;
    }
    
    @end
    

提交回复
热议问题