如何设置 UITabBarItem 的未选择色调,***包括系统项目***(iOS7) [英] How to set UITabBarItem's unselected tint, ***including system items*** (iOS7)

查看:14
本文介绍了如何设置 UITabBarItem 的未选择色调,***包括系统项目***(iOS7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(注意:我看到关于 SO 有几个类似的问题,但他们似乎都没有解决我想要更改自定义和系统 UITabBarItems 的未选择外观的具体问题.)

(NOTE: I see there are several similar questions on SO, but none of them seem to get at my specific issue of wanting to change the unselected appearance of both custom and system UITabBarItems.)

我在 iOS7 中工作.我有一个带有一些按钮的 UITabBar.其中一些是我的按钮,一些是系统按钮.示例:

I'm working in iOS7. I have a UITabBar with some buttons. Some of them are my buttons, some are system buttons. Example:

UITabBarItem *searchButton = [[UITabBarItem alloc] initWithTabBarSystemItem: UITabBarSystemItemSearch    tag: navSearchItem];
UITabBarItem *bookMkButton = [[UITabBarItem alloc] initWithTabBarSystemItem: UITabBarSystemItemBookmarks tag: navBookmarksItem];
UITabBarItem *homeButton   = [[UITabBarItem alloc] initWithTitle: @"Home"     image: [self tabBarImageNamed: @"home-tab"]     tag: navHomeItem];
UITabBarItem *setingButton = [[UITabBarItem alloc] initWithTitle: @"Settings" image: [self tabBarImageNamed: @"settings-tab"] tag: navSettingsItem];

navTabBar.items = @[ searchButton, homeButton, bookMkButton, setingButton];

我可以很容易地设置选定按钮的色调,使用:

I can set the selected-button tint easily enough, with:

[[UITabBar appearance] setSelectedImageTintColor: MY_FAVORITE_COLOR];

我可以将未选中的按钮文本颜色设置为白色:

I can set the unselected button text color to white:

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

我想要做的是将 UNSELECTED 按钮的图像色调设置为白色.我可以很容易地设置未选择的图像,但这仅适用于 my 按钮.我也想为系统按钮执行此操作.也就是说,我想要我的搜索 &书签按钮也是未选中的白色.

What I want to do is set the UNSELECTED button's image tint color to white. I could set the unselected image easily enough, but that only works for my buttons. I want to do this for the system buttons, also. That is, I want my search & bookmarks buttons to also be unselected-white.

我敢肯定,如果我尝试重新创建他们的图标来制作自定义按钮,Apple 会抱怨.文档非常具体,我们不应该做任何与 Apple 图标相似的事情.

I'm pretty sure Apple will complain if I try to recreate their icons to make custom buttons. The docs are pretty specific that we shouldn't do anything remotely resembling Apple's icons.

提示?

谢谢!

我想要 unselected=white 的原因是,在我设计的背景下,默认的灰色会使图标/文本在眼睛上很难看.

The reason I want unselected=white is that, against my designed background, the default grey makes the icons/text hard on the eyes.

推荐答案

我成功将自定义未选择的 UITabBarItem 图像 设置为白色的唯一方法是使用以下(白色)图像并加载它具有特定的渲染模式

The only way I was successful in setting a custom unselected UITabBarItem image to white was by using the following (white) image and loading it with a specific rendering mode

UIImage *tabImage = [[UIImage imageNamed:@"white_tab_item"] 
                      imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

self.tabItem.image = tabImage;

"tabItem" 是类的 UITabBarItem Outlet

"tabItem" being a UITabBarItem Outlet of the class

归功于 Aaron Brager 的回答:UITabBarController 未选中的图标图像色调

Credits go to Aaron Brager's answer: UITabBarController unselected icon image tint

这篇关于如何设置 UITabBarItem 的未选择色调,***包括系统项目***(iOS7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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