【iOS13问题】修改状态栏的颜色(亲测,有效)


- (UIStatusBarStyle)preferredStatusBarStyle {
    if (@available(iOS 13.0, *)) {
        return UIStatusBarStyleLightContent;
    } else {
        return UIStatusBarStyleLightContent;
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self setupStatusBarColor:[UIColor whiteColor]];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
   [self setupStatusBarColor:[UIColor blackColor]];
}

- (void)setupStatusBarColor:(UIColor *)color
{
    if (@available(iOS 13.0, *)) {
          if (!_statusBar) {
              UIWindow *keyWindow = [UIApplication sharedApplication].windows[0];
              _statusBar = [[UIView alloc] initWithFrame:keyWindow.windowScene.statusBarManager.statusBarFrame];
              [keyWindow addSubview:_statusBar];
          }
      } else {
        _statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
     }
      if ([_statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
          _statusBar.backgroundColor = color;
      }
}

- (void)dealloc{
    NSLog(@" dealloc  ");
    if (@available(ios 13.0, *)) {
        if (_statusBar) {
            [_statusBar removeFromSuperview];
            _statusBar = nil;
        }
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM