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 <= 0 || size.height <= 0) return nil;
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
3. UITableView
iOS15对于tableview,新增了sectionHeaderTopPadding作为列表每个部分标题上方的填充,默认增加22px,它的默认值是UITableViewAutomaticDimension,所以我们要将他设置为0,否则当我们的列表设置了section高度的列表会出现head高度增加的情况,适配方式:
if (@available(iOS 15.0, *)) {
self.sectionHeaderTopPadding = 0;
}
|