【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;
        }
    }
}

 

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

上一篇:JavaScript高级程序设计23.pdf


下一篇:【iOS bug记录】UICollectionviewCell刷新变得这么莫名其妙?