iOS - iOS15 适配

3、tableView的section

  • 出现的原因:

iOS15中,tableView会给每一个section的顶部(header以上)再加上一个22像素的高度,形成一个section和section之间的间距
新增的sectionHeaderTopPadding会使表头新增一段间隙,默认为UITableViewAutomaticDimension

  // 适配iOS15,tableView的section设置
  // iOS15中,tableView会给每一个section的顶部(header以上)再加上一个22像素的高度,形成一个section和section之间的间距
  // 新增的sectionHeaderTopPadding会使表头新增一段间隙,默认为UITableViewAutomaticDimension
  if (@available(iOS 15.0, *)) {
    
    
      UITableView.appearance.sectionHeaderTopPadding = 0;
  }

2、NavigationBar、tabbar背景颜色失效

背景色默认透明,滑动时显示,tabbar背景色透明

  • 出现的原因:

在iOS13更新的API针对navigationBar、tabbar分别新增了新的属性专门管理这些滑动时候产生的颜色透明等等信息,由于设置导航栏和tabbar没有使用standardAppearancescrollEdgeAppearance这些设置,所以在iOS15上失效

  • 解决方案:
  • 2.1、导航栏
    UIColor *titleColor = UIColor.whiteColor;
    UIColor *navBgColor = BaseThemeColor;
    //标题颜色
    [[UINavigationBar appearance] setTitleTextAttributes:@{
    
    NSForegroundColorAttributeName:titleColor}];
    //设置导航栏背景色
    [UINavigationBar appearance].barTintColor = navBgColor;
    if (@available(iOS 15.0, *)) {
    
    
        NSDictionary *titleTextAttributes = @{
    
    NSFontAttributeName:JhFontsize(18), NSForegroundColorAttributeName:titleColor};
        UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
        appearance.backgroundColor = navBgColor;
        appearance.titleTextAttributes = titleTextAttributes;
        // standardAppearance:常规状态, 标准外观,iOS15之后不设置的时候,导航栏背景透明
        [UINavigationBar appearance].standardAppearance = appearance;
        // scrollEdgeAppearance:被scrollview向下拉的状态, 滚动时外观,不设置的时候,使用标准外观
        [UINavigationBar appearance].scrollEdgeAppearance = appearance;
    }
  • 2.2、tabbar
	UIColor *normalColor = BaseBlackTextColor;
    UIColor *selectColor = BaseThemeColor;
    
    UITabBarItem *item = [UITabBarItem appearance];
    // 普通状态下的文字属性
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSFontAttributeName] = JhFontsize(10);
    normalAttrs[NSForegroundColorAttributeName] = normalColor;
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    // iOS13适配,处理未选中颜色失效
    if (@available(iOS 13.0, *)) {
    
    
        [[UITabBar appearance] setUnselectedItemTintColor:normalColor];
    }
    // 选中状态下的文字属性
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = JhFontsize(10);
    selectedAttrs[NSForegroundColorAttributeName] = selectColor;
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    // iOS15适配,处理tabBar背景和分割线透明,选中颜色失效
    if (@available(iOS 15.0, *)) {
    
    
        UITabBarAppearance * appearance = [UITabBarAppearance new];
        appearance.stackedLayoutAppearance.normal.titleTextAttributes = normalAttrs;
        appearance.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttrs;
        UITabBar.appearance.standardAppearance = appearance;
        UITabBar.appearance.scrollEdgeAppearance = appearance;
    }

1、Xcode13 必须用New Build System模式

File -> Workspace Setting ->New Build System
这个模式下项目中或有多余的md ,plist文件需要删除

一些工程不得不变成 New Build System引发编译不过的解决方法:
Build Phases里某些地方的 Run script勾选上 For install builds only即可。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/iotjin/article/details/121163531