美文网首页
iOS 13屏幕旋转之后 UITabBarItem 颜色错误

iOS 13屏幕旋转之后 UITabBarItem 颜色错误

作者: 花飞雨勿 | 来源:发表于2020-01-08 10:12 被阅读0次

屏幕旋转之后,UITabBarItem选种颜色不正确

    // 适配iOS13导致的bug
    if (@available(iOS 13.0, *)) {
        // iOS 13以上
        self.tabBar.tintColor = kThemeColor;
        self.tabBar.unselectedItemTintColor = [UIColor z_colorWithRGBHex: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:[UIColor z_colorWithRGBHex:0x999999]} forState:UIControlStateNormal];
        [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:kThemeColor} forState:UIControlStateSelected];
    }

相关文章

网友评论

      本文标题:iOS 13屏幕旋转之后 UITabBarItem 颜色错误

      本文链接:https://www.haomeiwen.com/subject/wlbjactx.html