为UITabBar中的选定选项卡设置颜色颜色 [英] setting tint color for selected tab in UITabBar

查看:85
本文介绍了为UITabBar中的选定选项卡设置颜色颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode 5 Dev Preview 2中,我能够执行以下操作:

In Xcode 5 Dev Preview 2, I was able to execute the following:

[[UITabBar appearance] setTintColor:[UIColor whiteColor]];//所选图片和文字的颜色(白色)

[[UITabBar appearance] setTintColor:[UIColor whiteColor]]; //the color of the selected image and text (white)

在Xcode 5 Dev Preview 3中,同一行代码引发异常(请参见下文).异常表明我可能要使用'barTintColor'-但我不希望使用-因为这是整个UITabBar的颜色.如何在UITabBar中设置所选图像和文本的颜色?

In Xcode 5 Dev Preview 3, the same line of code throws an exception (see below). The exception indicates that I may want to use 'barTintColor' - but I do not - as this is the color of the overall UITabBar. How can I set the color of the selected image and text in a UITabBar?

Xcode 5 Dev Preview 3中的新异常:

The new exception in Xcode 5 Dev Preview 3:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-setTintColor: is not allowed for use with the appearance proxy. Perhaps you want to use the barTintColor property.'

谢谢

推荐答案

我在最新的Xcode 5(5.0.2)中看不到此问题,但我确实知道您想调用其他方法来设置选定的图像颜色的颜色取决于您是在iOS 6还是7上运行.这是我的一个应用程序中的一些示例代码:

I'm not seeing this with the latest Xcode 5 (5.0.2), but I do know that you want to call different methods to set the selected image tint color depending on whether you're running on iOS 6 or 7. Here's some sample code from one of my apps:

if ([RFSUtilities isIOS7OrHigher])
{
    [[UITabBar appearance] setTintColor:[UIColor whiteColor]];
}
else
{
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
}

+[RFSUtilities isIOS7OrHigher]仅使用希望这会有所帮助!

这篇关于为UITabBar中的选定选项卡设置颜色颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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