- (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问题】修改状态栏的颜色(亲测,有效)
最新推荐文章于 2022-11-30 17:54:25 发布