一年一系統(tǒng)撰豺,一年一適配。
今天我們來講一下iOS15適配的相關(guān)地方刻蚯。
導(dǎo)航欄適配
iOS 15中互墓,導(dǎo)航欄的問題比較明顯,調(diào)試之后發(fā)現(xiàn)是UINavigationBar部分屬性的設(shè)置在iOS 15上是無效的缤谎,查看導(dǎo)航欄特性API抒倚,蘋果對(duì)導(dǎo)航欄的性能做了優(yōu)化,默認(rèn)情況下弓千,如果導(dǎo)航欄與視圖沒有折疊衡便,導(dǎo)航欄的背景透明,如果系統(tǒng)檢測(cè)到有重疊的話洋访,會(huì)變成毛玻璃的效果镣陕。
note:UINavigationBarAppearance是iOS 13更新的API,
iOS 15 navigationBar的相關(guān)屬性設(shè)置要通過實(shí)例UINavigationBarAppearance來實(shí)現(xiàn)姻政。
在iOS 13 UINavigationBar新增了scrollEdgeAppearance屬性呆抑,但在iOS 14及更早的版本中此屬性只應(yīng)用在大標(biāo)題導(dǎo)航欄上。在iOS 15中此屬性適用于所有導(dǎo)航欄汁展。
//配置導(dǎo)航欄
- (void)configNav {
//設(shè)置Nav的背景色和title色
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
[appearance setBackgroundColor:[UIColor pageBackgroundColor]];
[appearance setBackgroundImage:[self imageWithColor:[UIColor pageBackgroundColor]]];
[appearance setShadowImage:[self imageWithColor:[UIColor pageBackgroundColor]]];
appearance.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18.0f weight:UIFontWeightSemibold],NSForegroundColorAttributeName: [UIColor blackColor]};
// [appearance setBackIndicatorImage:[UIImage imageNamed:@"image_common_navBackBlack"] transitionMaskImage:[UIImage imageNamed:@"image_common_navBackBlack"]];
[[UINavigationBar appearance] setScrollEdgeAppearance: appearance];
[[UINavigationBar appearance] setStandardAppearance:appearance];
}
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
[navigationBarAppearance setBackgroundImage:[self imageWithColor:[UIColor pageBackgroundColor]] forBarMetrics:UIBarMetricsDefault];
[navigationBarAppearance setShadowImage:[self imageWithColor:[UIColor pageBackgroundColor]]];
[navigationBarAppearance setTintColor:[UIColor colorWithRed:109/255.0 green:114/255.0 blue:120/255.0 alpha:1.0]];
[navigationBarAppearance setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemMediumFont:18],NSForegroundColorAttributeName: [UIColor colorWithRed:109/255.0 green:114/255.0 blue:120/255.0 alpha:1.0]}];
// navigationBarAppearance.backIndicatorImage = [UIImage imageNamed:@"image_common_navBackBlack"];
// navigationBarAppearance.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"image_common_navBackBlack"];
// [[UITextField appearance] setTintColor:[UIColor colorWithHexString:System_color]];
// [[UITextView appearance] setTintColor:[UIColor colorWithHexString:System_color]];
[[UISearchBar appearance] setBackgroundImage:[self imageWithColor:[UIColor whiteColor]] forBarPosition:0 barMetrics:UIBarMetricsDefault];
}
TabBar 適配
tabbar背景顏色設(shè)置失效鹊碍,字體設(shè)置失效,陰影設(shè)置失效問題
背景色設(shè)置失效食绿,需要用UITabBarAppearance來設(shè)置
if (@available(iOS 13.0, *)) {
UITabBarAppearance * appearance = [[UITabBarAppearance alloc] init];
// 背景色
appearance.backgroundColor = [UIColor whiteColor];
self.tabBar.standardAppearance = appearance;
if (@available(iOS 15.0, *)) {
self.tabBar.scrollEdgeAppearance = appearance;
}
}
TableView 適配
UITableView Section的header增加默認(rèn)間距
if (@available(iOS 15.0, *)) {
_tableView.sectionHeaderTopPadding = 0;
}
目前更新的就是這些了侈咕,有遺漏的會(huì)進(jìn)行再次補(bǔ)充。