iOS 7/8如何设置标签栏文字颜色

时间:2014-12-22 18:33:03

标签: ios ios7 ios8 uitabbarcontroller

我在app delegate中为标签栏设置了颜色:

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

它完美无缺,但我还需要分别设置文字颜色。我希望我的图像是红色的,但文字必须是白色。

这可能吗?

2 个答案:

答案 0 :(得分:5)

更改uitabbaritem使用的setTitleTextAttributes的颜色我希望此代码可以帮助您:

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

更改图像tintcolor:

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

答案 1 :(得分:1)

答案: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];