【问题标题】:iOS 7/8 how to set tab bar text color [duplicate]iOS 7/8如何设置标签栏文本颜色[重复]
【发布时间】:2015-02-20 21:24:32
【问题描述】:

我已经在应用委托中设置了标签栏的颜色:

[[UITabBar appearance] setTintColor:[UIColor redColor]];

效果很好,但我还需要单独设置文本颜色。我希望我的图像带有红色,但文字必须是白色。

这有可能吗?

【问题讨论】:

标签: ios ios7 ios8 uitabbarcontroller


【解决方案1】:

改变uitabbaritem的颜色使用setTitleTextAttributes希望这段代码对你有帮助:

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [[uicolor whitecolor] }
       forState:UIControlStateSelected];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }
     forState:UIControlStateNormal];

改变图像色调:

[[UITabBar appearance] setTintColor:[UIColor redcolor]];

【讨论】:

    【解决方案2】:

    https://stackoverflow.com/a/18734795/860343 的答案涵盖了您可能需要对标签栏项目进行的大部分编辑。

    简而言之,代码如下:

    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
                                                    NSForegroundColorAttributeName : appTintColor
                                                    } forState:UIControlStateSelected];
    
    
    // doing this results in an easier to read unselected state then the default iOS 7 one
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
                                                        NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
                                                        } forState:UIControlStateNormal];
    

    【讨论】:

      猜你喜欢
      • 2013-10-04
      • 2013-10-11
      • 2018-09-14
      • 1970-01-01
      • 2015-07-13
      • 1970-01-01
      • 2015-07-14
      • 2013-09-18
      • 2013-09-27
      相关资源
      最近更新 更多