1. 关闭暗黑模式
在iOS发布iOS13系统后,新增了黑暗模式,当用户把黑暗模式打开后,app会出现很多显示问题,最让人头疼就是导航栏的现实与控件的背景颜色现实,为了解决这个问题,我建议在没有需求强制要求下,我们将黑暗模式直接屏蔽比较好,当黑暗模式开启后,我们在我们的程序的info.plist中添加以下配置:(禁用黑暗模式)
在info.plist中的Appearance配置UIUserInterfaceStyleLight或者Light
代码添加,在info.plist中添加UIViewControllerBasedStatusBarAppearance配置
<key>UIUserInterfaceStyle</key>
<string>Light</string>
2. 修改状态栏背景色
- (void)setStatusBarBackgroundColor:(UIColor *)color {
if(@available(iOS 13.0, *)) {
NSSet *set = [UIApplication sharedApplication].connectedScenes;
UIWindowScene *windowScene = [set anyObject];
UIStatusBarManager *statusBarManager = windowScene.statusBarManager;
static UIView *statusBar =nil;
if(!statusBar) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
statusBar = [[UIView alloc] initWithFrame:statusBarManager.statusBarFrame] ;
[[Util getRootWindow] addSubview:statusBar];
statusBar.backgroundColor= color;
});
}else{
statusBar.backgroundColor= color;
}
}else{
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor= color;
}
}
}