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

2020-01-08  本文已影响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];
    }
上一篇下一篇

猜你喜欢

热点阅读