setting tint color for selected tab in UITabBar

ⅰ亾dé卋堺 提交于 2020-01-13 08:46:12

问题


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

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

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?

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.'

Thank you


回答1:


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]];
}

The +[RFSUtilities isIOS7OrHigher] just checks to see whether we're running on iOS 7 or above with the proper version check:

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

Hope this helps!




回答2:


Just add tintColor with color type in User Defined Runtime Attribute of the UITabBar class.

Still looking for the similar approach for inactive tabs... Anyone know?



来源:https://stackoverflow.com/questions/20783193/setting-tint-color-for-selected-tab-in-uitabbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!