iOS 15适配总结

嗨,这里是逻辑iOS技术号:一个让知识变得感性,让学习变得轻松!活跃的技术小站,希望给你的生活与技术带来意思不一样!关注公众号,回复“   面试题”,即可领取更多大厂面试题型哦~ 小逻辑相信我们的生活不止眼前的苟且,还有我们向往的诗和大厂高薪工作~

 

 

tabbar及navicationbar的背景颜色问题

问题:从ios14升级到ios15会出现 导航栏背景颜色失效

原因:因为设置颜色方法在ios15中失效

--在iOS13更新的API中新增了针对navigationBar,tabbar分别新增了新的属性专门管理这些滑动时候产生的颜色透明等等信息,由于我们应用兼容iOS10以上,对于导航栏的设置还没有使用UINavigationBarAppearance和UITabBarAppearance,但在更新的iOS15上失效,所以就变得设置失效

 

//设置navigationBar颜色self.navigationController.navigationBar.barTintColor = [UIColor blueColor];//设置tabBar背景色self.tabBarController.tabBar.backgroundColor = [UIColor blueColor];//设置tabBarItem字体颜色NSMutableDictionary<NSAttributedStringKey, id> *normalAttributes = [NSMutableDictionary dictionary];[normalAttributes setValue:[UIColor blueColor] forKey:NSForegroundColorAttributeName];[self.tabBarItem setTitleTextAttributes:normalAttributes.copy forState:UIControlStateNormal];[self.tabBarItem setTitleTextAttributes:normalAttributes.copy forState:UIControlStateSelected];

(滑动显示更多)

解决方法--重新设置相关属性

tabBar

 

UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];//tabBaritem title选中状态颜色appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{    NSForegroundColorAttributeName:[UIColor blueColor],};//tabBaritem title未选中状态颜色appearance.stackedLayoutAppearance.normal.titleTextAttributes = @{    NSForegroundColorAttributeName:[UIColor blueColor],};//tabBar背景颜色appearance.backgroundColor = [UIColor blackColor];self.tabBarItem.scrollEdgeAppearance = appearance;self.tabBarItem.standardAppearance = appearance;

(滑动显示更多)

 

其中 standardAppearance和scrollEdgeAppearance等的区别 standardAppearance --- 常规状态scrollEdgeAppearance --- 小屏幕手机横屏时的状态scrollEdgeAppearance --- 呗scrollview向下拉的状态

(滑动显示更多)

navigationBar

 

UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];appearance.backgroundColor = [UIColor blackColor];self.navigationBar.standardAppearance = appearance;self.navigationBar.scrollEdgeAppearance = appearance;

(滑动显示更多)

tableview新属性

-sectionHeaderTopPadding

官方支持

 

/// Determines if the table view allows its cells to become focused./// When tableView:canFocusRowAtIndexPath: is implemented, its return value takes precedence over this method./// Defaults to a system derived value based on platform and other properties of the table view.@property (nonatomic, getter=isPrefetchingEnabled) BOOL prefetchingEnablediOS 15中tableView会给每一个section的顶部(header以上)再加上一个22像素的高度,形成一个section和section之间的间距

(滑动显示更多)

使用

 

为了配合以前的开发习惯,我们只需要在创建实例的时候进行对间距的设置即可if (@available(iOS 15.0, *)) { tableView.sectionHeaderTopPadding = 0;} 或者全局设置if (@available(iOS 15.0, *)) { [UITableView appearance].sectionHeaderTopPadding = 0;}

(滑动显示更多)

来源:稀土掘金

作者:edwardyk

链接:https://juejin.cn/post/7012558803614826526

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值