iOS15適配小結(jié)
1、tabbar及navicationbar的背景顏色問題
問題:從ios14升級到ios15會出現(xiàn) 導航欄背景顏色失效
原因:因為設(shè)置顏色方法在ios15中失效
--在iOS13更新的API中新增了針對navigationBar,tabbar分別新增了新的屬性專門管理這些滑動時候產(chǎn)生的顏色透明等等信息,由于我們應用兼容iOS10以上,對于導航欄的設(shè)置還沒有使用UINavigationBarAppearance和UITabBarAppearance,但在更新的iOS15上失效,所以就變得設(shè)置失效
//設(shè)置navigationBar顏色 self.navigationController.navigationBar.barTintColor = [UIColor blueColor]; //設(shè)置tabBar背景色 self.tabBarController.tabBar.backgroundColor = [UIColor blueColor]; //設(shè)置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];
解決方法--重新設(shè)置相關(guān)屬性
tabBar
UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init]; //tabBaritem title選中狀態(tài)顏色 appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{ NSForegroundColorAttributeName:[UIColor blueColor], }; //tabBaritem title未選中狀態(tài)顏色 appearance.stackedLayoutAppearance.normal.titleTextAttributes = @{ NSForegroundColorAttributeName:[UIColor blueColor], }; //tabBar背景顏色 appearance.backgroundColor = [UIColor blackColor]; self.tabBarItem.scrollEdgeAppearance = appearance; self.tabBarItem.standardAppearance = appearance;
其中 standardAppearance和scrollEdgeAppearance等的區(qū)別
- standardAppearance --- 常規(guī)狀態(tài)
- scrollEdgeAppearance --- 小屏幕手機橫屏時的狀態(tài)
- scrollEdgeAppearance --- 唄scrollview向下拉的狀態(tài)
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之間的間距
使用
為了配合以前的開發(fā)習慣,我們只需要在創(chuàng)建實例的時候進行對間距的設(shè)置即可
if (@available(iOS 15.0, *)) { tableView.sectionHeaderTopPadding = 0; }
或者全局設(shè)置
if (@available(iOS 15.0, *)) { [UITableView appearance].sectionHeaderTopPadding = 0; }
到此這篇關(guān)于iOS15適配小結(jié)的文章就介紹到這了,更多相關(guān)iOS15適配內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用UItableview在iOS應用開發(fā)中實現(xiàn)好友列表功能
這篇文章主要介紹了使用UItableview在iOS應用開發(fā)中實現(xiàn)一個好友列表功能的方法,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-12-12iOS 使用UITextField自定義搜索框 實現(xiàn)用戶輸入完之后“實時搜索”功能
這篇文章主要介紹了iOS 使用UITextField自定義搜索框 實現(xiàn)用戶輸入完之后“實時搜索”功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03利用iOS開發(fā)實現(xiàn)翻轉(zhuǎn)撲克牌動畫的方法
這篇文章主要給大家介紹了關(guān)于利用iOS開發(fā)實現(xiàn)翻撲克牌動畫的方法,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面來跟著小編一起學習學習吧。2017-07-07IOS中快速集成短信SDK驗證開發(fā)(SMSSDK),IOS開發(fā)中如何設(shè)置手機短信驗證碼
這篇文章主要介紹了IOS中快速集成短信SDK驗證開發(fā)(SMSSDK),IOS開發(fā)中如何設(shè)置手機短信驗證碼 的相關(guān)資料,需要的朋友可以參考下2016-01-01