iOS 15 适配

一年一系统,一年一适配。
今天我们来讲一下iOS15适配的相关地方。
导航栏适配
iOS 15中,导航栏的问题比较明显,调试之后发现是UINavigationBar部分属性的设置在iOS 15上是无效的,查看导航栏特性API,苹果对导航栏的性能做了优化,默认情况下,如果导航栏与视图没有折叠,导航栏的背景透明,如果系统检测到有重叠的话,会变成毛玻璃的效果。
note:UINavigationBarAppearance是iOS 13更新的API,
iOS 15 navigationBar的相关属性设置要通过实例UINavigationBarAppearance来实现。

在iOS 13 UINavigationBar新增了scrollEdgeAppearance属性,但在iOS 14及更早的版本中此属性只应用在大标题导航栏上。在iOS 15中此属性适用于所有导航栏。

//配置导航栏
- (void)configNav {
    //设置Nav的背景色和title色
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        [appearance setBackgroundColor:[UIColor pageBackgroundColor]];
        [appearance setBackgroundImage:[self imageWithColor:[UIColor pageBackgroundColor]]];
        [appearance setShadowImage:[self imageWithColor:[UIColor pageBackgroundColor]]];
        appearance.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18.0f weight:UIFontWeightSemibold],NSForegroundColorAttributeName: [UIColor blackColor]};
//        [appearance setBackIndicatorImage:[UIImage imageNamed:@"image_common_navBackBlack"] transitionMaskImage:[UIImage imageNamed:@"image_common_navBackBlack"]];
        [[UINavigationBar appearance] setScrollEdgeAppearance: appearance];
        [[UINavigationBar appearance] setStandardAppearance:appearance];

    }
    
    UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
    [navigationBarAppearance setBackgroundImage:[self imageWithColor:[UIColor pageBackgroundColor]] forBarMetrics:UIBarMetricsDefault];
    [navigationBarAppearance setShadowImage:[self imageWithColor:[UIColor pageBackgroundColor]]];
    [navigationBarAppearance setTintColor:[UIColor colorWithRed:109/255.0 green:114/255.0 blue:120/255.0 alpha:1.0]];
    [navigationBarAppearance setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemMediumFont:18],NSForegroundColorAttributeName: [UIColor colorWithRed:109/255.0 green:114/255.0 blue:120/255.0 alpha:1.0]}];
//    navigationBarAppearance.backIndicatorImage = [UIImage imageNamed:@"image_common_navBackBlack"];
//    navigationBarAppearance.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"image_common_navBackBlack"];

//    [[UITextField appearance] setTintColor:[UIColor colorWithHexString:System_color]];
//    [[UITextView appearance] setTintColor:[UIColor colorWithHexString:System_color]];
    [[UISearchBar appearance] setBackgroundImage:[self imageWithColor:[UIColor whiteColor]] forBarPosition:0 barMetrics:UIBarMetricsDefault];
}

TabBar 适配
tabbar背景颜色设置失效,字体设置失效,阴影设置失效问题
背景色设置失效,需要用UITabBarAppearance来设置

if (@available(iOS 13.0, *)) {
            UITabBarAppearance * appearance = [[UITabBarAppearance alloc] init];
            // 背景色
            appearance.backgroundColor = [UIColor whiteColor];
            self.tabBar.standardAppearance = appearance;
            if (@available(iOS 15.0, *)) {
                self.tabBar.scrollEdgeAppearance = appearance;
            }
        }

TableView 适配
UITableView Section的header增加默认间距

if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }

目前更新的就是这些了,有遗漏的会进行再次补充。

你可能感兴趣的:(iOS 15 适配)