ios – 为UITabBar中的选定选项卡设置色调颜色

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

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

在Xcode 5 Dev Preview 3中,同一行代码抛出异常(见下文).异常表明我可能想要使用’barTintColor’ – 但我没有 – 因为这是整个UITabBar的颜色.如何在UITabBar中设置所选图像和文本的颜色?

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上运行.这里有一些来自我的某个应用的示例代码:
if ([RFSUtilities isIOS7OrHigher])
{
    [[UITabBar appearance] setTintColor:[UIColor whiteColor]];
}
else
{
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
}

[RFSUtilities isIOS7OrHigher]只是检查我们是否使用the proper version check在iOS 7或更高版本上运行:

+ (BOOL)isIOS7OrHigher
{
    float versionNumber = floor(NSFoundationVersionNumber);
    return versionNumber > NSFoundationVersionNumber_iOS_6_1;
}

希望这可以帮助!

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...