The correct way to set a light status bar text color in iOS 7 based on different ViewControllers

后端 未结 8 1234
死守一世寂寞
死守一世寂寞 2020-12-25 14:52

I need to let a specific ViewController embedded in an UINavigationController to have light status bar text color (but other ViewControllers to beh

相关标签:
8条回答
  • 2020-12-25 15:20

    Currently you can only do light and dark. To change to light do.

    1. Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file.

    2. In the viewDidLoad method do [self setNeedsStatusBarAppearanceUpdate];

    3. Add the this method:

    -(UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent; }

    To change it back to dark change the UIStatusBarStyleLightContent to UIStatusBarStyleDefault

    0 讨论(0)
  • 2020-12-25 15:26

    For people having this problem with a UINavigationController I can recommend creating a custom UINavigationController and implementing the preferredStatusBarStyle on it like this:

    - (UIStatusBarStyle)preferredStatusBarStyle
    {
        return [self.topViewController preferredStatusBarStyle];
    }
    

    That way the statusbar style will be that of the top view controller. Now you can implement the view controller's preferredStatusBarStyle anyway you like.

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