iOS15 新特性兼容适配

您所在的位置:网站首页 iOS15新特性开发 iOS15 新特性兼容适配

iOS15 新特性兼容适配

2023-09-30 05:55| 来源: 网络整理| 查看: 265

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


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3