在 iOS 2.0 --> 9.0 状态栏会产生二种
1、UIStatusBarStyleDefault
2、UIStatusBarStyleLightContent
///之前项目设置状态栏都是这种,但这种在iOS9.0后就被遗弃
iOS:[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
swift:UIApplication.shared.statusBarStyle = .lightContent
UIApplication.shared.statusBarStyle = .default
/// 'setStatusBarStyle:' is deprecated: first deprecated in iOS 9.0 - Use -[UIViewController preferredStatusBarStyle]
因为在iOS9.0就被遗弃了,这些方法会报警告,所以强迫症不用了,根据他的提示用
###preferredStatusBarStyle
@property(nonatomic, readonly) UIStatusBarStyle preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarStyleDefault
而且最低支持 iOS 7,用户手机系统适配方面没问题.
开始着手用在ViewController 里面用preferredStatusBarStyle
- (UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
由于之前需要在info.plist 中 View controller-based status bar appearance 设置为NO 才能改变状态栏的颜色;现在是不需要设置或者设置为YES 该方法才会走,对应的颜色也变了