最近iPhone13发布,iOS15系统发布,自己脑残升级了Xcode到最新版13,导致UINavigationBar的背景失效。
解决办法:
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
//设置背景色
appearance.backgroundColor = APP_NAVIGATIONBAR_TINTCOLOR;
//设置标题颜色
appearance.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
//设置返回按键和返回字体为白色
self.navigationBar.tintColor=[UIColor whiteColor];
self.navigationBar.standardAppearance = appearance;
self.navigationBar.scrollEdgeAppearance = appearance;
} else {
UINavigationBar *bar = [UINavigationBar appearance];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav"] forBarMetrics:UIBarMetricsDefault];
bar.barTintColor = APP_NAVIGATIONBAR_TINTCOLOR;
bar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar setTranslucent:YES];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont systemFontOfSize:0.0001],NSFontAttributeName,nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
}