要更改iOS 7中未选中的UITabBar图标的颜色? [英] To change the color of unselected UITabBar icon in iOS 7?

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

问题描述

我知道此问题也已在早些时候提出,但我仍然无法在互联网上搜索解决方案。

I know this question has been asked earlier as well, but still i didn't get any solution searching the solution on internet.

我提到了以下帖子:

如何在iOS 7中更改tabBarItems的文本和图标颜色?
只能使用<$ c $更改所选的图标颜色c> tintColor 。

How can I change the text and icon colors for tabBarItems in iOS 7? Only able to change the selected icons color using tintColor.

如何更改iOS 7中未选中的标签栏项目的颜色? 在这里他们写了他们自己的 GozTabBar 继承自UIView的课程

How to change the color of unselected tab bar items in iOS 7? In this they have written their own GozTabBar class inherited from UIView

我想更改<$的默认灰色c $ c> UITabBar 图标处于未选择状态时。

I want to changes the default gray color of UITabBar icon when its in unselected state.

任何帮助都将受到高度赞赏。在此先感谢。

Any help would be highly appreciated. Thanks in advance.

推荐答案

我假设您不想使用tintColor更改颜色?另一种选择是使用两个看起来完全相同但颜色不同的图像。一个图像是选定的选项卡,另一个是未选中的。

I'm assuming that you do not want to change the color using tintColor? Another option is to use two images that look exactly the same, but differ in color. One image is the selected tab, the other is unselected.

AppDelegate.m - (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 函数,试试这个。

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;

// repeat for every tab, but increment the index each time
UITabBarItem *firstTab = [tabBar.items objectAtIndex:0];

// also repeat for every tab
firstTab.image = [[UIImage imageNamed:@"someImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
firstTab.selectedImage = [[UIImage imageNamed:@"someImageSelected.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

编辑:对于那些没有标签栏控制器作为根视图控制器的人,你可以像这样抓住控制器,其余代码是相同的。

For those who don't have the tab bar controller as their root view controller, you can grab the controller like this and the rest of the code is the same.

UITabBarController * tabBarController = self.tabBarController;

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

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