Demo地址
Demo中包含本人学习的所有资料,还有一些封装的Pod组件,欢迎下载Star,如果有错误的地方,还请指出,详情查看 README.md
问题:xcode14 使用
self.navigationBar.barTintColor = mainColor;
self.toolbar.barTintColor = mainColor;
方式配置背景色出现异常问题,具体表现为列表滚动到边缘地带,导航栏、toolbar背景色变成透明。
更新了xcode14后,运行我的项目,发现相册选择功能的 navigationbar
和 toolbar
的背景色在 tableview
滚动到边缘的时候展示异常,变成了透明。随后我下载了 iOS15
的模拟器,发现还是不对,就想到应该不是 iOS
系统版本的问题,猜测大概是 xcode
的问题。经过一系列问题排查和测试,发现 xcode14
的 navigationbar
和 toolbar
的样式需要使用 UIBarAppearance
来处理,不能在使用 barTintColor
来设置背景色,包括其他设置背景图这些都不在适合。UIBarAppearance
是 iOS 13
后引入的新配置大概使用方法如下
- (void)configUIBarAppearance {
if (@available(iOS 13.0, *)) {
///NaviBar
UINavigationBarAppearance *naviBarAppearance = [[UINavigationBarAppearance alloc] init];
if (self.navigationBar.isTranslucent) {
UIColor *barTintColor = self.navigationBar.barTintColor;
naviBarAppearance.backgroundColor = [barTintColor colorWithAlphaComponent:0.85];
} else {
naviBarAppearance.backgroundColor = self.navigationBar.barTintColor;
}
naviBarAppearance.titleTextAttributes = self.navigationBar.titleTextAttributes;
self.navigationBar.standardAppearance = naviBarAppearance;
self.navigationBar.scrollEdgeAppearance = naviBarAppearance;
///ToolBar
UIToolbarAppearance *toolBarAppearance = [[UIToolbarAppearance alloc] init];
if (self.toolbar.isTranslucent) {
UIColor *barTintColor = self.toolbar.barTintColor;
toolBarAppearance.backgroundColor = [barTintColor colorWithAlphaComponent:0.85];
} else {
toolBarAppearance.backgroundColor = self.navigationBar.barTintColor;
}
self.toolbar.standardAppearance = toolBarAppearance;
if (@available(iOS 15.0, *)) {
self.toolbar.scrollEdgeAppearance = toolBarAppearance;
}
}
}