override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent;
}
使用上述代码在任何ViewController中为特定的ViewController设置状态栏颜色为白色,在iOS8中对我来说是行不通的。有什么建议吗?使用UIApplication。shared应用方法,在信息中需要更改后颜色更改。Plist为整个应用程序。
// Change the colour of status bar from black to white
UIApplication.sharedApplication().statusBarStyle = .LightContent
我怎么能改变一些必要的和特定的视图控制器的状态栏颜色?
有两种情况:
1.显示导航栏
1)添加1uiviewcontrollerbasedstatusbarappearance /基于视图控制器的状态栏外观到你的信息。Plist, set value为true。
2)在你的自定义NavigationController类中覆盖preferredStatusBarStyle属性:
class NavigationController : UINavigationController {
override var preferredStatusBarStyle : UIStatusBarStyle {
if let topVC = viewControllers.last {
//return the status property of each VC, look at step 2
return topVC.preferredStatusBarStyle
}
return .default
}
3)覆盖preferredStatusBarStyle在你的特定视图控制器:
override var preferredStatusBarStyle : UIStatusBarStyle {
return .lightContent
}
2.隐藏导航栏
1)同上
2)不需要以上第二步,直接执行第三步。
override var preferredStatusBarStyle : UIStatusBarStyle {
return .lightContent
}