我已经检查了堆栈溢出中给出的答案。
喜欢这种方法:prefersStatusBarHidden
-(BOOL)prefersStatusBarHidden {
return [self.navigationController prefersStatusBarHidden];
}
答案 0 :(得分:0)
创建并导入一个类别的导航控制器,如下所示
#import <UIKit/UIKit.h>
@interface UINavigationController (StatusBarStyle)
- (void)setDefaultStatusBar;
- (void)setLightStatusBar;
@end
#import "UINavigationController+StatusBarStyle.h"
@implementation UINavigationController (StatusBarStyle)
BOOL isLight;
- (void)setDefaultStatusBar {
isLight=NO;
[self setNeedsStatusBarAppearanceUpdate];
}
- (void)setLightStatusBar {
isLight=YES;
[self setNeedsStatusBarAppearanceUpdate];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
if (isLight) {
return UIStatusBarStyleLightContent;
}
else{
return UIStatusBarStyleDefault;
}
}
@end
从viewDidLoad或视图控制器中具有父[self.navigationController setDefaultStatusBar]
[self.navigationController setLightStatusBar]
或UINavigationController