本篇讲的是preferredStatusBarStyle的设置方式
1。 删除 infolist view controller-based status bar appearance的设置(如果是UIApplication.shared.setStatusBarStyle(.default, animated: true),需要设置为NO,但此方法在iOS9.0废弃)
2.若是在appdelegate里面,把Viewcontrooler设置为导航控制器,或者设置tabbar为导航控制器,则需要做UINavigationController的扩展
extension UINavigationController{
openoverridevarchildForStatusBarStyle:UIViewController?{
return self.topViewController
}
}
3 直接贴代码
classViewController:UIViewController{
private var statusBarStyle:UIStatusBarStyle= .lightContent{
didSet{
self.setNeedsStatusBarAppearanceUpdate();
}
}
overridevarpreferredStatusBarStyle:UIStatusBarStyle{
return statusBarStyle;
}
overridefunctouchesBegan(_touches:Set, with event:UIEvent?) {
if statusBarStyle == .default{
statusBarStyle= .lightContent;
}else{
statusBarStyle= .default;
}
}