iOS 13适配:设置UITabBarItem上title颜色

适配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];
}

仅供参考,欢迎补充

你可能感兴趣的:(iOS 13适配:设置UITabBarItem上title颜色)