iOS15适配

作者: Mr_Zhou | 来源:发表于2021-12-06 17:48 被阅读0次

用Xcode13编译工程后,需要进行适配(后续遇到继续更新),记录如下:

  • NavigationBar
  • TabBar
  • TableView
  1. iOS设置导航栏 NavigationBar
// 修改NarBar背景
    if (@available(iOS 15.0, *)) {
        
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        // 背景色
        appearance.backgroundColor = [UIColor whiteColor];
        // 去掉半透明效果
        appearance.backgroundEffect = nil;
        // 标题字体颜色及大小
        appearance.titleTextAttributes = @{
            NSForegroundColorAttributeName : [UIColor blackColor],
            NSFontAttributeName : [UIFont boldSystemFontOfSize:18],
        };
        // 设置导航栏下边界分割线透明
        appearance.shadowImage = [[UIImage alloc] init];
        // 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线)
        appearance.shadowColor = [UIColor clearColor];
        // standardAppearance:常规状态, 标准外观,iOS15之后不设置的时候,导航栏背景透明
        self.navigationController.navigationBar.standardAppearance = appearance;
        // scrollEdgeAppearance:被scrollview向下拉的状态, 滚动时外观,不设置的时候,使用标准外观
        self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
    }
  1. 适配 TabBar
// 修改tabbar背景
if (@available(iOS 15.0, *)) {
        
        UITabBarAppearance *appearance = [UITabBarAppearance new];
        //tabBar背景颜色
        appearance.backgroundColor = [UIColor whiteColor];
       // 去掉半透明效果
        appearance.backgroundEffect = nil;
       // tabBaritem title选中状态颜色
       appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{
            NSForegroundColorAttributeName:KColorFromRGB(0x53A2F8),
            NSFontAttributeName:[UIFont systemFontOfSize:12],
        };
        //tabBaritem title未选中状态颜色
        appearance.stackedLayoutAppearance.normal.titleTextAttributes =  @{
            NSForegroundColorAttributeName:KColorFromRGB(0x7E7E7E),
            NSFontAttributeName:[UIFont systemFontOfSize:12],
        };
        self.tabBar.scrollEdgeAppearance = appearance;
        self.tabBar.standardAppearance = appearance;
}

针对一些控制器在push时隐藏导航栏,在pop时显示导航栏的处理

// 对导航栏的处理
+(void)adaptationNavBar
{
    if (@available(iOS 13.0, *)) {
           
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
          
        [appearance setShadowImage:[[UIImage alloc] init]];
          
        [appearance setBackgroundColor:[UIColor whiteColor]];
          
        // 隐藏分割线 设置一个透明或者纯色的图片 设置nil 或者 [UIImage new]无效
        [appearance setBackgroundImage:[self imageWithColor:[UIColor whiteColor]]];
          
        [appearance setShadowImage:[self imageWithColor:[UIColor whiteColor]]];
          
        [[UINavigationBar appearance] setScrollEdgeAppearance: appearance];
       
    }
}

+(UIImage *)imageWithColor:(UIColor *)color {
    
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(3, 3), NO, [UIScreen mainScreen].scale);
    
    UIBezierPath* bezierPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 3, 3)];
   
    [color setFill];
    
    [bezierPath fill];
    
    UIImage* img = UIGraphicsGetImageFromCurrentImageContext();
   
    return img;
}
  1. TableView 增加了sectionHeaderTopPadding属性,TableView section header增加22像素的高度
if (@available(iOS 15.0, *)) {
     self.tableView.sectionHeaderTopPadding = 0;
}

有些界面我直接把导航栏隐藏,自己画了导航栏,这种方法简单粗暴,发现导航栏出现的问题都解决了。um..... 就这么多,有问题请指出。

相关文章

  • html2canvas在ios15系统截图空白并刷新

    随着ios15系统的出现,项目适配ios15系统兼容性。 发现html2canvas在iOS15系统中截图空白并在...

  • iOS15 适配更新总结

    本文主要分享一下 iOS15 上适配方案,仅做开发记录使用,开发过程中通过使用陆续增加。 iOS15 的适配,很重...

  • iOS开发技巧之:iOS15 适配更新总结

    本文主要分享一下 iOS15 上适配方案,仅做开发记录使用,开发过程中通过使用陆续增加。 iOS15 的适配,很重...

  • iOS15适配

    iOS15适配主要是以下几点:UINavigationController、UITabBarController、...

  • iOS15适配

    对于iOS15适配汇总以及遇到的问题 注意:以下适配内容,必须适配的会以"必须"标出 UITableView Se...

  • iOS 15 适配笔记

    前言 环境 在 升级xcode 13.0 之后,正式开始支持 iOS15,就需要做适配 iOS15了,在 xcod...

  • 日期篇

    1. NSDateFormatter 1.1 系统适配 iOS15以下dateFormat = @"HH:mm" ...

  • iOS15适配

    以iOS15和xcode13为环境基础,iOS15适配的一些更改和调整。 UINavigationBar UITa...

  • iOS15适配

    以iOS15和xcode13为环境基础,iOS15适配的一些更改和调整。 UINavigationBar UITa...

  • IOS15审核最新详细版

    IOS15适配 导航栏UINavigationBar 从 iOS 15 开始,UINavigationBar、UI...

网友评论

    本文标题:iOS15适配

    本文链接:https://www.haomeiwen.com/subject/gncnxrtx.html