iOS15下重寫的導(dǎo)航欄變白失效,無論怎么設(shè)置都沒有效果,解決方案如下:
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *navigationBarAppearance = [[UINavigationBarAppearance alloc]init];
[navigationBarAppearance configureWithOpaqueBackground];
[navigationBarAppearance setBackgroundImage:[UIImage imageNamed:@"nav_bg"]];
navigationBarAppearance.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:FONT_SIZE(18)};
self.navigationBar.scrollEdgeAppearance = navigationBarAppearance;
self.navigationBar.standardAppearance = navigationBarAppearance;
}
寫法1:
//重寫的導(dǎo)航欄這樣設(shè)置
self.navigationBar.scrollEdgeAppearance = navigationBarAppearance;
self.navigationBar.standardAppearance = navigationBarAppearance;
寫法2:
//控制器中這樣設(shè)置
self.navigationController.navigationBar.scrollEdgeAppearance = navigationBarAppearance;
self.navigationController.navigationBar.standardAppearance = navigationBarAppearance;