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
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!
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