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;
        }

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文作为自己准备适配iOS15所用,在开始适配之前,先去学习各位同学的文章,记录在此备用。 1、导航栏UINavi...
    iOS_zy阅读 14,499评论 5 61
  • 对于iOS15适配汇总以及遇到的问题 注意:以下适配内容,必须适配的会以"必须"标出 UITableView Se...
    HF_K阅读 2,884评论 1 4
  • 苹果前两天推出了iOS 15。秋天都等不及~~ 相关链接:ios 15.0 适配问题:NavigationBar和...
    阳光下的叶子呵阅读 8,122评论 3 13
  • 背景 按照往年新系统发布的时间规律,新的系统预计在9月20日左右发布,目前beta版本已经更新到beta6。想必都...
    冬冬吧阅读 15,574评论 17 20
  • 16宿命:用概率思维提高你的胜算 以前的我是风险厌恶者,不喜欢去冒险,但是人生放弃了冒险,也就放弃了无数的可能。 ...
    yichen大刀阅读 6,098评论 0 4