美文网首页
iOS13 Tabbar选中切换文字渲染失效返回蓝色的问题

iOS13 Tabbar选中切换文字渲染失效返回蓝色的问题

作者: Westrice | 来源:发表于2019-11-02 16:45 被阅读0次

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

        UITabBarItem *item = [UITabBarItem appearance];
        [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
        [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    • iOS13后文档中对#UIBbarAppearance#对象有说明,在设置的对象属性时需要初始化并设置一个UIBarAppearance或则子类来设置其对象属性

    iOS13设置的代码如下:

    if (@available(iOS 13.0, *)) {
            // titColor就是选中的颜色,iOS13后默认的颜色是灰色,所以一般不需要设置默认颜色
            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];
        }
    

    相关文章

      网友评论

          本文标题:iOS13 Tabbar选中切换文字渲染失效返回蓝色的问题

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