如何更改iOS 7选项卡栏上的非活动图标/文本 colored颜色 ?灰色的那个.

在此处输入图像描述

推荐答案

In every first ViewController for each TabBar:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // changing the unselected image color, you should change the selected image 
    // color if you want them to be different
    self.tabBarItem.selectedImage = [[UIImage imageNamed:@"yourImage_selectedImage"]
    imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    self.tabBarItem.image = [[UIImage imageNamed:@"yourImage_image"] 
    imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

这段代码的线索是"UIImageRenderingModeAlwaysOriginal":

Rendering Modes by Apple Documentation:

UIImageRenderingModeAutomatic,          // Use the default rendering mode for the context where the image is used    
UIImageRenderingModeAlwaysOriginal,     // Always draw the original image, without treating it as a template
UIImageRenderingModeAlwaysTemplate,     // Always draw the image as a template image, ignoring its color information

To change text color:

在AppDelegate中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Add this if you only want to change Selected Image color 
    // and/or selected image text
    [[UITabBar appearance] setTintColor:[UIColor redColor]];

    // Add this code to change StateNormal text Color,
    [UITabBarItem.appearance setTitleTextAttributes:
    @{NSForegroundColorAttributeName : [UIColor greenColor]} 
    forState:UIControlStateNormal];

    // then if StateSelected should be different, you should add this code
    [UITabBarItem.appearance setTitleTextAttributes:
    @{NSForegroundColorAttributeName : [UIColor purpleColor]} 
    forState:UIControlStateSelected];

    return YES;
}

Objective-c相关问答推荐

iOS 应用 Display Recorder 如何在不使用私有 API 的情况下录制屏幕?

UISearchbar 键盘搜索按钮操作

如何更改图像 tintColor

如何在 iOS 中拨打电话?

带有 AVPlayer 的多个视频

在运行时判断 iOS 版本?

在 Xcode 5 中运行代码覆盖时出现数十个profiling:invalid arc tag

我们可以在 UIPageViewController 中自定义页面指示器吗?

Grand Central Dispatch (GCD) 与 performSelector - 需要更好的解释

AdMob 因 [GADObjectPrivate changeState:] 崩溃:无法识别的 Select 器

反转 NSString 文本

将块存储在数组中

如何推送两个视图控制器但只为第二个设置动画过渡?

NSURLConnection sendAsynchronousRequest:queue:completionHandler:连续发出多个请求?

Objective-C中的继承和类别有什么区别

在 iOS UILabel 上设置 BOLD 字体

从视图中删除所有子图层

UIImageView 并不总是为模板图像着色

如何阻止 NSNotification 中的观察者调用两次?

无法在 iOS7 上将 UITextField 添加到 UIAlertView ...在 iOS 6 中有效