iOS13暗黑模式下状态栏设置UIStatusBarStyleD

2021-07-24  本文已影响0人  倒着游的鱼

iOS13暗黑模式下,默认的状态栏颜色是白色 ,所以设置UIStatusBarStyleDefault,是无法把状态栏改为黑色的,需要使用iOS13的新属性UIStatusBarStyleDarkContent

//UIViewController对象的视图已经加入到窗口时调用
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

//UIViewController对象的视图即将消失、被覆盖或是隐藏时调用
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if (@available(iOS 13.0, *)) {
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
    } else {
        // Fallback on earlier versions
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    }
}

上一篇下一篇

猜你喜欢

热点阅读