美文网首页
Xcode 11 tabBar 在 push 之后回来字体颜色

Xcode 11 tabBar 在 push 之后回来字体颜色

作者: Coder_张三 | 来源:发表于2019-11-04 10:55 被阅读0次

    升级 Xcode 11 后在 push 一个控制器再回来发现字体颜色没有设置成功。


    WX20191104-105136@2x.png

    这个时候需要在 UITabBarController 那里写上这么一句代码。
    OC:

    // 设置常态字体的颜色
        if (@available(iOS 10.0, *)) {
            [[UITabBar appearance] setUnselectedItemTintColor:[UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0]];
        }
        
        // 2> 设置字体选中样式
        NSMutableDictionary *textAttributesSelected = [NSMutableDictionary dictionary];
        textAttributesSelected[NSForegroundColorAttributeName] = [UIColor orangeColor];
        [vc.tabBarItem setTitleTextAttributes:textAttributesSelected forState:UIControlStateSelected];
    

    Swift:

    // 4.设置字体样式
            if #available(iOS 10.0, *) {
                tabBar.unselectedItemTintColor = UIColor.init(r: 153, g: 153, b: 153)
            }
            vc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor:UIColor.orange], for: .selected)
    

    相关文章

      网友评论

          本文标题:Xcode 11 tabBar 在 push 之后回来字体颜色

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