如何更改iOS7中未选择的tabbaritem颜色? [英] How to change the unselected tabbaritem color in iOS7?

查看:165
本文介绍了如何更改iOS7中未选择的tabbaritem颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 7之前我使用过

Before iOS 7 I used

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

但是现在它只绘制了所选项目,我已经阅读了一些建议但我无法完成这样做,我也使用过它:

But now it only paint the selected item, I have read some suggestions but I can not fin how to do it, I used this too:

[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"openbookwp4.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"openbookwp4.png"]];

将我想要的图标放入我想要的颜色,但仅在我选择了该标签后例如,当我打开应用程序时,选项卡看起来很正常,但是在我按下第二个选项卡并返回到第一个选项卡后,第二个选项卡现在具有我想要的颜色。没有图像很难解释,但我无法发布图像...

this put the icon I want, with the color I want, but only after I selected that tab for example, when I open the app the tab looks normal, but after I press the second tab and return to the first, the second tab now has the color I want. It is hard to explain without images, but I can not post images...

推荐答案

此代码适用于iOS 7。 / p>

This code works on iOS 7.

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
                                                    NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
                                                    } forState:UIControlStateNormal];

根据需要设置前景色。

还要影响未选择的标签栏图标:

To affect also the non selected tabbar icons:

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor greenColor], UITextAttributeTextColor, nil]
                                         forState:UIControlStateNormal];

如果它不起作用,唯一的方法是选择和未选择状态的图像:

If it does not work the only way is with images for selected and unselected states:

// set selected and unselected icons
UITabBarItem *item = [self.tabBar.items objectAtIndex:0];

// this way, the icon gets rendered as it is (thus, it needs to be green in this example)
item.image = [[UIImage imageNamed:@"unselected-icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

// this icon is used for selected tab and it will get tinted as defined in self.tabBar.tintColor
item.selectedImage = [UIImage imageNamed:@"selected-icon.png"];

这篇关于如何更改iOS7中未选择的tabbaritem颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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