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];
}
发布了129 篇原创文章 · 获赞 11 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/Batac_Lee/article/details/103453916
今日推荐