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

cod*_*cat 8 iphone xcode objective-c uitabbar ios

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

[[UITabBar appearance] 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.'
Run Code Online (Sandbox Code Playgroud)

谢谢

Jos*_*own 18

我没有看到最新的Xcode 5(5.0.2),但我知道你想调用不同的方法设置所选的图像色调颜色取决于你是在iOS 6或7上运行.这里有一些来自我的某个应用的示例代码:

if ([RFSUtilities isIOS7OrHigher])
{
    [[UITabBar appearance] setTintColor:[UIColor whiteColor]];
}
else
{
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
}
Run Code Online (Sandbox Code Playgroud)

+[RFSUtilities isIOS7OrHigher]刚刚检查,看看我们在iOS 7或以上,是否正在运行正确的版本检查:

+ (BOOL)isIOS7OrHigher
{
    float versionNumber = floor(NSFoundationVersionNumber);
    return versionNumber > NSFoundationVersionNumber_iOS_6_1;
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!