更改默认值“未选择"UITabBarItem 图片颜色 [英] Change Default "Not Selected" UITabBarItem Image Color

查看:28
本文介绍了更改默认值“未选择"UITabBarItem 图片颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何更改 UITabBarItem 中图标的未选中"或未高亮状态?

how do we change the "Not Selected" or the unhiglighted state of the icons in UITabBarItem?

我尝试设置 UITabBarItem.appearance().setTitleTextAttributes(:) 但它只会改变文本颜色.

I tried setting the UITabBarItem.appearance().setTitleTextAttributes(:) but it only changes the text color.

有什么想法吗?

推荐答案

如果您想在 iOS 7 及更高版本中更改默认设置,您必须实际使用不同的图标(使用您喜欢的未选中标签的颜色)和设置文本的颜色.您可以应用此调整,而不是创建两组图标:

If you want to change the default in iOS 7 and above, you have to actually use different icons (in the color you like to have for unselected tabs) and set the color of the text. Instead of creating two sets of icons, you could apply this tweak:

// set the selected colors
[self.tabBar setTintColor:[UIColor whiteColor]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];


UIColor * unselectedColor = [UIColor colorWithRed:184/255.0f green:224/255.0f blue:242/255.0f alpha:1.0f];

// set color of unselected text
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:unselectedColor, NSForegroundColorAttributeName, nil]
                                     forState:UIControlStateNormal];

// generate a tinted unselected image based on image passed via the storyboard
for(UITabBarItem *item in self.tabBar.items) {
   // use the UIImage category code for the imageWithColor: method
   item.image = [[item.selectedImage imageWithColor:unselectedColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

来源.

这篇关于更改默认值“未选择"UITabBarItem 图片颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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