Colors 如何在iOS 7.1上更改UITabBar上图像和标签的颜色?

Colors 如何在iOS 7.1上更改UITabBar上图像和标签的颜色?,colors,uitabbar,uitabbaritem,ios7.1,Colors,Uitabbar,Uitabbaritem,Ios7.1,如何在iOS 7.1上更改uitabar上图像和标签的颜色?在iOS 7上,我可以通过Tintproperty来实现。但在iOS 7.1上,它不起作用。uitabaritem从来没有tint属性。没有内置类具有tint属性。这里没有什么变化 在iOS 7和7.1中,UITabBar具有tintColor属性,因为它是UIView。这会在选中时更改图像和标签的色调 - (void)viewDidLoad { [super viewDidLoad]; [[UITabBar appea

如何在iOS 7.1上更改
uitabar
上图像和标签的颜色?在iOS 7上,我可以通过
Tint
property来实现。但在iOS 7.1上,它不起作用。

uitabaritem从来没有
tint
属性。没有内置类具有
tint
属性。这里没有什么变化


在iOS 7和7.1中,UITabBar具有
tintColor
属性,因为它是UIView。

这会在选中时更改图像和标签的色调

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UITabBar appearance] setTintColor:[UIColor redColor]];
}

它在iOS 7和iOS 7.1中的工作方式相同

在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;
}
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
在每个ViewController中:(如果要更改未选择的图像颜色)

此代码的线索是“UIImageRenderingModeAlwaysOriginal”:

苹果文档提供的渲染模式:

- (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;
}
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