第一步设置
如果只是单独UIViewController文件,我们可以做如下简单设置,就可以实现StatusBarStyle的设置
// 在info.plist中设置属性
Status bar is initially hidden: YES
View controller-based status bar appearance: YES
// 在ViewController中增加代码
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
有的页面没效果
做了上述设置,可惜有时候却没效果,这是为啥?
经过UI查看,发现我们的UIWindow.rootViewController是UINavigationController,那只在UIViewController中的设置就无效了。
查看下UINavigationController的API,发现可以通过如下接口设置
// 需要继承UINavigationController,并增加如下代码
- (UIViewController *)childViewControllerForStatusBarStyle {
return self.topViewController;
}
网友评论