1.用xcode13编译工程后,导航栏的问题比较明显,原因是UINavigationBar部分属性的设置在iOS15上是无效的。
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *bar = [UINavigationBarAppearance new];
[bar setBackgroundColor:RPBackGroundColor];
[bar setBackgroundImage:[UIImage new]];
bar.shadowColor = [UIColor clearColor];
self.navigationController.navigationBar.standardAppearance = bar;
self.navigationController.navigationBar.scrollEdgeAppearance = self.navigationController.navigationBar.standardAppearance;
}else{
//导航底部的分割线置为空白
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
}
2. 设置导航栏颜色 setBarTintColor 方法失效
- (void)navgationSetBarTintColor:(UIColor *)color{
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *bar = [UINavigationBarAppearance new];
[bar setBackgroundColor:color];
[bar setBackgroundImage:[UIImage new]];
bar.shadowColor = [UIColor clearColor];
self.navigationController.navigationBar.standardAppearance = bar;
self.navigationController.navigationBar.scrollEdgeAppearance = self.navigationController.navigationBar.standardAppearance;
}else{
[self.navigationController.navigationBar setBarTintColor:color];
}
}
3.tabbar的问题和navigationBar的问题属于同一类,tabbar背景颜色设置失效,字体设置失效,阴影设置失效问题
if (@available(iOS 15.0, *)) {
UITabBarAppearance *appearance = [UITabBarAppearance new];
appearance.backgroundColor = [UIColor whiteColor];
// 设置未被选中的颜色
appearance.stackedLayoutAppearance.normal.titleTextAttributes = attrs;
// 设置被选中时的颜色
appearance.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttrs;
[appearance setBackgroundColor:[UIColor whiteColor]];
[appearance setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]]];
[appearance setShadowImage:[UIImage imageWithColor:hexColor(@"#F4F4FF")]];
self.tabBar.standardAppearance = appearance;
self.tabBar.scrollEdgeAppearance = self.tabBar.standardAppearance;
}else{
UITabBarItem *item = [UITabBarItem appearance];
[item setTitleTextAttributes:attrs forState:UIControlStateNormal];
[item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
}
+ (UIImage *)imageWithColor:(UIColor *)color {
CGSize size = CGSizeMake(1, 1);
if (!color || size.width |