最近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];
}
|