StatusBar的全局设置,需要首先在info.plist
中设置View controller-based status bar appearance
为NO,关掉按界面设置status bar 显示。
方法一:在Target下的Deployment Info中不勾选/勾选Hide status bar
方法二:代码设置
[UIApplication sharedApplication].statusBarHidden = YES;
方法一:在Target下的Deployment Info中设置Status Bar Style
方法二:代码设置
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
首先在info.plist
中设置View controller-based status bar appearance
为YES,打开按界面设置status bar 显示。
普通的ViewController设置:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
如果是UINavigaitonController,则需要添加一个继承自UINavigationController的子类,在子类中设置如下代码,使用子类来控制。或者添加UINavigaitonController的Category,在Category中设置如下代码
原因是:UIViewController嵌套在UINavigaitonController中时,会优先调用UINavigationController的preferredStatusBarStyle
,所以直接在UIViewController中设置是不生效的。
- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.topViewController preferredStatusBarStyle];
}
- (UIViewController *)childViewControllerForStatusBarStyle {
return self.topViewController;
}
modal出来的viewController设置了prefersStatusBarHidden不生效的问题,需要设置modalPresentationCapturesStatusBarAppearance为YES;
@implementation TargetViewController
- (instancetype)init {
self = [super init];
if (self) {
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
self.modalPresentationCapturesStatusBarAppearance = YES;
}
return self;
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。