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