iOS 13 Tabbar 选中push返回文字渲染返回蓝色 和去除上面黑线

一、设置文字的颜色 

如果在iOS13中使用以下代码设置Tabbar文字渲染在点击其他item切换或则push返回的时候是会失效的,字体颜色是会返回系统默认的蓝色

    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];

iOS13后文档中对#UIBbarAppearance#对象有说明,在设置的对象属性时需要初始化并设置一个UIBarAppearance或则子类来设置其对象属性

正确设置方式:

if (@available(iOS 13.0, *)) {
        // titColor就是选中的颜色
        self.tabBar.tintColor = [UIColor redColor];
  //如果需要设置默认颜色可以使用setUnselectedItemTintColor来设置未选中颜色
       [self.tabBar setUnselectedItemTintColor:UIColor redColor];
    } else {
        
    // 统一给所有的UITabBarItem设置文字属性
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    }

二、去除上面的线

if (@available(iOS 13.0,*)) {
            
            UITabBarAppearance * appeearance = self.standardAppearance;
            appeearance.backgroundImage = [UIImage imageWithColor:[UIColor clearColor]];;
            appeearance.shadowImage = [UIImage imageWithColor:[UIColor clearColor]];;
            self.standardAppearance = appeearance;
            
        }
        else{
            self.backgroundImage = [UIImage new];
            self.shadowImage = [UIImage new];
        }
        
        //imageWithColor是为UIImage写的一个分类方法:根据颜色生成一张图片,其中 [UIImage new] 方法已不在适用。

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值