问题描述
(注意:我看到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 按钮的图像色调为白色。我可以轻松地设置未选择的图像,但这仅适用于我的按钮。我也想为系统按钮执行此操作。也就是说,我想要我的搜索和书签按钮也可以取消选择 - 白色。
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.
提示?
谢谢!
编辑:我想要取消选择=白色的原因是,在我设计的背景下,默认灰色会使图标/文字变硬眼睛。
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出口
"tabItem" being a UITabBarItem Outlet of the class
致Aaron Brager的答案:
Credits go to Aaron Brager's answer:UITabBarController unselected icon image tint
这篇关于如何设置UITabBarItem的未选色,***包括系统项***(iOS7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!