如何在iOS 7中更改tabBarItems的文本和图标颜色? [英] How can I change the text and icon colors for tabBarItems in iOS 7?

查看:96
本文介绍了如何在iOS 7中更改tabBarItems的文本和图标颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS 7中更改UITabBar和UITabBarItems的文本和图标颜色?对于未选中的tabbar项,默认的灰色文本看起来很暗,很难阅读。

How can I change the text and icon colors for UITabBar and UITabBarItems in iOS 7? The default gray text seems dim and hard to read for unselected tabbar items.

推荐答案

你需要做两件事:

1)如果你想自定义TabBar本身,你需要为tabBarController设置barTintColor:

1) If you want to customize the TabBar itself, you need to set the barTintColor for the tabBarController:

    // this will generate a black tab bar
    tabBarController.tabBar.barTintColor = [UIColor blackColor];

    // this will give selected icons and text your apps tint color
    tabBarController.tabBar.tintColor = appTintColor;  // appTintColor is a UIColor *

2)为你想要的每个状态设置tabBarItem文本外观覆盖:

2) Set the tabBarItem text appearance for each state that you want to override:

[[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];

这篇关于如何在iOS 7中更改tabBarItems的文本和图标颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆