在iOS的plist文件中可以配置 默认的状态栏样式,其key为UIStatusBarStyle
其值有如下几种,所谓content就是指内容的模式,dark conent就是指 导航栏文字是黑色的
image.png
其中还有一个关键的key:UIViewControllerBasedStatusBarAppearance
A Boolean value indicating whether the status bar appearance is based on the style preferred for the current view controller.一个布尔值,指示状态栏外观是否基于当前视图控制器的首选样式。
也就是说,当UIViewControllerBasedStatusBarAppearance为YES时,状态栏根据控制器的偏好而发生变化,也就是 首选以谁为准的问题
//即**UIViewControllerBasedStatusBarAppearance为YES,下面的生效情况如下,
//** 如果**UIViewControllerBasedStatusBarAppearance为NO时,则上面的生效与否相反**
//控制器的偏好代码生效
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDarkContent;
}
//而直接修改状态栏的代码不生效
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
当控制器偏好优先级高时,需要设置控制器的偏好来控制
// 状态栏的显示隐藏
- (BOOL)prefersStatusBarHidden
{
return NO;
}
// 状态栏的样式
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDarkContent;
}
// 手动触发状态栏更新
[self setNeedsStatusBarAppearanceUpdate];
当应用状态栏优先级高时,可以直接设置
[UIApplication sharedApplication].statusBarHidden = NO;
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;