Demo地址
Demo中包含本人學習的所有資料,還有一些封裝的Pod組件,歡迎下載Star,如果有錯誤的地方,還請指出,詳情查看 README.md
問題:xcode14 使用
self.navigationBar.barTintColor = mainColor;
self.toolbar.barTintColor = mainColor;
方式配置背景色出現(xiàn)異常問題,具體表現(xiàn)為列表滾動到邊緣地帶,導航欄、toolbar背景色變成透明。
更新了xcode14后,運行我的項目,發(fā)現(xiàn)相冊選擇功能的 navigationbar 和 toolbar 的背景色在 tableview 滾動到邊緣的時候展示異常,變成了透明。隨后我下載了 iOS15 的模擬器,發(fā)現(xiàn)還是不對,就想到應該不是 iOS 系統(tǒng)版本的問題,猜測大概是 xcode 的問題。經過一系列問題排查和測試,發(fā)現(xiàn) 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;
}
}
}