适配iOS 13
发现设置UITabBarItem
的颜色,未选中状态下无效为默认颜色,选中状态下有效,但是push
后再返回,tabBarItem
选中颜色变为系统蓝色,修改后如下:
// 适配iOS13导致的bug
if (@available(iOS 13.0, *)) {
// iOS 13以上
self.tabBar.tintColor = RGB_HEX(0xfb5400);
self.tabBar.unselectedItemTintColor = RGB_HEX(0x999999);
UITabBarItem *item = [UITabBarItem appearance];
item.titlePositionAdjustment = UIOffsetMake(0, -2);
[item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateNormal];
[item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateSelected];
} else {
// iOS 13以下
UITabBarItem *item = [UITabBarItem appearance];
item.titlePositionAdjustment = UIOffsetMake(0, -2);
[item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:RGB_HEX(0x999999)} forState:UIControlStateNormal];
[item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:RGB_HEX(0xfb5400)} forState:UIControlStateSelected];
}
仅供参考,欢迎补充