Open dream5788 opened 4 years ago
- (void)setStatusBarBackgroundColor:(UIColor *)color {
if (@available(iOS 13.0, *)) {
UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager;
id _statusBar = nil;
if ([statusBarManager respondsToSelector:@selector(createLocalStatusBar)]) {
UIView *_localStatusBar = [statusBarManager performSelector:@selector(createLocalStatusBar)];
if ([_localStatusBar respondsToSelector:@selector(statusBar)]) {
_statusBar = [_localStatusBar performSelector:@selector(statusBar)];
}
}
if (_statusBar) {
if (([(UIView *)_statusBar respondsToSelector:@selector(setBackgroundColor:)])) {
[(UIView *)_statusBar setBackgroundColor:color];
}
}
} else {
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
}
}
吧baseViewController中得- (void)setStatusBarBackgroundColor:(UIColor *)color这个方法里面的内容注释了即可,原因是iOS13以后,系统会自动调用status bar
App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead 什么情况,一跑就闪退。