iOS中修改状态颜色在iOS9后官方废弃了下面这种方法:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
//'setStatusBarStyle:' is deprecated: first deprecated in iOS 9.0 - Use -[UIViewController preferredStatusBarStyle]
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
iOS9以后使用下面这种方式来修改颜色
- (UIStatusBarStyle)preferredStatusBarStyle{
NSLog(@"go style");
return UIStatusBarStyleLightContent;
}
如果你的页面有导航栏,则使用上面这这种方式将无法生效,针对有导航栏的,需要在baseNavigationController中加入重写childViewControllerForStatusBarStyle方法
- (UIViewController *)childViewControllerForStatusBarStyle {
return self.topViewController;
}
注意:重写preferredStatusBarStyle修改状态栏如果要生效,一定要在info.plist中配置View controller-based status bar appearance=YES