The correct way to set a light status bar text col

2019-02-03 05:46发布

I need to let a specific ViewController embedded in an UINavigationController to have light status bar text color (but other ViewControllers to behave differently). I am aware of at least 3 methods, none of which however work in my case.

  1. How to change Status Bar text color in iOS 7, the method is primarily:

    • Set the UIViewControllerBasedStatusBarAppearance to YES in the plist
    • In viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];
    • Add the following method:

      - (UIStatusBarStyle)preferredStatusBarStyle{ 
            return UIStatusBarStyleLightContent; 
        }
      

    Running on iOS 7.0.3, this method does not work for me, since even after I have implemented all 3 steps correctly, preferredStatusBarStyle is never called.

  2. UIStatusBarStyle PreferredStatusBarStyle does not work on iOS 7, the method is primarily:

    Setting your navigationBar’s barStyle to UIBarStyleBlackTranslucent will give white status bar text (ie. UIStatusBarStyleLightContent), and UIBarStyleDefault will give black status bar text (ie. UIStatusBarStyleDefault).

    This method works fair and square on iPhone, but not on iPad.

  3. Setting the UIViewControllerBasedStatusBarAppearance to NO in the plist, and use

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    

    This clearly doesn't apply in this case, since I need to only specify different status bar colors for two of the ViewControllers.

Thanks for all help!

7条回答
狗以群分
2楼-- · 2019-02-03 06:44

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

查看更多
登录 后发表回答