iOS15適配小結(jié)
1、tabbar及navicationbar的背景顏色問(wèn)題
問(wèn)題:從ios14升級(jí)到ios15會(huì)出現(xiàn) 導(dǎo)航欄背景顏色失效


原因:因?yàn)樵O(shè)置顏色方法在ios15中失效
--在iOS13更新的API中新增了針對(duì)navigationBar,tabbar分別新增了新的屬性專門(mén)管理這些滑動(dòng)時(shí)候產(chǎn)生的顏色透明等等信息,由于我們應(yīng)用兼容iOS10以上,對(duì)于導(dǎo)航欄的設(shè)置還沒(méi)有使用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 --- 小屏幕手機(jī)橫屏?xí)r的狀態(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會(huì)給每一個(gè)section的頂部(header以上)再加上一個(gè)22像素的高度,形成一個(gè)section和section之間的間距
使用
為了配合以前的開(kāi)發(fā)習(xí)慣,我們只需要在創(chuàng)建實(shí)例的時(shí)候進(jìn)行對(duì)間距的設(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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
iOS開(kāi)發(fā)之手勢(shì)識(shí)別實(shí)例
本篇文章主要介紹了iOS開(kāi)發(fā)之手勢(shì)識(shí)別實(shí)例,具有一定的參考價(jià)值,有需要的可以了解一下。2016-11-11
IOS 開(kāi)發(fā)之PickerView自定義視圖的實(shí)例詳解
這篇文章主要介紹了IOS 開(kāi)發(fā)之PickerView自定義視圖的實(shí)例詳解的相關(guān)資料,這里提供實(shí)例幫助大家學(xué)習(xí)理解這部分知識(shí),需要的朋友可以參考下2017-08-08
iOS常見(jiàn)算法以及應(yīng)用知識(shí)點(diǎn)總結(jié)
在本篇文章里小編給大家分享的是關(guān)于iOS常見(jiàn)算法以及應(yīng)用知識(shí)點(diǎn)總結(jié),有興趣的朋友們學(xué)習(xí)下。2019-10-10
深入講解iOS開(kāi)發(fā)中的UIViewController
這篇文章主要介紹了iOS開(kāi)發(fā)中的UIViewController,其中以UIViewController作為著重講解,需要的朋友可以參考下2015-09-09
詳解ios監(jiān)聽(tīng)reloadData刷新列表完畢的時(shí)機(jī)
這篇文章主要介紹了詳解ios監(jiān)聽(tīng)reloadData刷新列表完畢的時(shí)機(jī),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11
iOS8調(diào)用相機(jī)報(bào)警告Snapshotting a view的解決方法
這篇文章主要介紹了iOS8調(diào)用相機(jī)報(bào)警告Snapshotting a view……的解決方法 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11
IOS身份證識(shí)別(OCR源碼)詳解及實(shí)例代碼
這篇文章主要介紹了IOS身份證識(shí)別(OCR源碼)詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-03-03
iOS中UIAlertController設(shè)置自定義標(biāo)題與內(nèi)容的方法
UIAlertController是iOS8推出的新概念,取代了之前的 UIAlertView和UIActionSheet(雖然現(xiàn)在仍可以使用,但是會(huì)有警告)。下面這篇文章主要給大家介紹了關(guān)于iOS中UIAlertController如何設(shè)置自定義標(biāo)題與內(nèi)容的相關(guān)資料,需要的朋友可以參考下。2017-10-10

