如何隐藏ios 10中的状态栏?

时间:2017-08-04 10:20:41

标签: ios objective-c xcode8 statusbar appdelegate

我已经检查了堆栈溢出中给出的答案。   喜欢这种方法:prefersStatusBarHidden

      -(BOOL)prefersStatusBarHidden {
       return [self.navigationController prefersStatusBarHidden];
       }

1 个答案:

答案 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