UITabBar在iOS 13下會(huì)有問題,比如:
1、當(dāng)push進(jìn)入某個(gè)頁面再pop回來時(shí),tabBar的文字顏色就會(huì)變成系統(tǒng)自帶的藍(lán)色
2、隱藏tabBar分割線的方法已經(jīng)失效了
下面針對(duì)這兩個(gè)問題做下適配
1、在原有代碼基礎(chǔ)上直接添加如下代碼
if (@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];
appearance.stackedLayoutAppearance.normal.titleTextAttributes = attribute;
appearance.stackedLayoutAppearance.selected.titleTextAttributes = selectAttribute;
self.tabBar.standardAppearance = appearance;
}
2、iOS 13之前,隱藏TabBar分割線的方法是
self.tabBar.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
self.tabBar.shadowImage = [UIImage new];
但在iOS 13中該方法無效,所以該做如下適配
if (@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];
appearance.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
appearance.shadowColor = [UIColor clearColor];
self.tabBar.standardAppearance = appearance;
} else {
self.tabBar.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
self.tabBar.shadowImage = [UIImage new];
}