可以设置的地方有两个:plist设置里面 和 程序代码里
一.View controller-based status bar appearance设置为YES,则[UIApplication sharedApplication].statusBarStyle 无效。可以使用下面3个方法修改
- (UIStatusBarStyle)preferredStatusBarStyle;
- (UIViewController *)childViewControllerForStatusBarStyle;
- (void)setNeedsStatusBarAppearanceUpdate
- 在vc中重写preferredStatusBarStyle方法。
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}
2.在viewDidload中调用:[self setNeedsStatusBarAppearanceUpdate];
在NavigationController里上面的方法没有用,只会调用navigation controller中的preferredStatusBarStyle方法
可通过自定义一个nav类。重写他的preferredStatusBarStyle方法
- (UIStatusBarStyle)preferredStatusBarStyle {
return self.topViewController.preferredStatusBarStyle;
}
二.在info.plist中,View controller-based status bar appearance 设为 NO,这时application的设置优先级最高,
状态栏字体颜色由下面属性设置
[UIApplication sharedApplication].statusBarStyle
*iOS9以后api说明
// Setting the statusBarStyle does nothing if your application is using the default UIViewController-based status bar system.
@property(readwrite, nonatomic) UIStatusBarStyle statusBarStyle NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]");
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]");