iOS15适配小结
程序员文章站
2022-06-21 23:14:00
目录1、tabbar及navicationbar的背景颜色问题原因:因为设置颜色方法在ios15中失效解决方法--重新设置相关属性2、tableview新属性-sectionheadertoppadd...
1、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;
2、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 prefetchingenabled
ios 15中tableview会给每一个section的顶部(header以上)再加上一个22像素的高度,形成一个section和section之间的间距
使用
为了配合以前的开发习惯,我们只需要在创建实例的时候进行对间距的设置即可
if (@available(ios 15.0, *)) { tableview.sectionheadertoppadding = 0; }
或者全局设置
if (@available(ios 15.0, *)) { [uitableview appearance].sectionheadertoppadding = 0; }
到此这篇关于ios15适配小结的文章就介绍到这了,更多相关ios15适配内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: 红枣泡酒的功效与作用你知道吗
下一篇: 宜宾本地人推荐美食