Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting tint color for selected tab in UITabBar

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

like image 943
codercat Avatar asked Dec 26 '13 10:12

codercat


People also ask

How do you change the selected tab color in flutter?

To change tab bar background color in Flutter, first, create a getter to return the TabBar widget and then wrap the TabBar widget inside the PreferredSize -> Material widget. Inside the Material add the color property and set the color of your choice.

How do I change the color of a tab bar in Swift?

backgroundColor = UIColor(red:1, green:0, blue:0, alpha:1) / UITabBar. appearance(). tintColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1) // New!! func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {...}


1 Answers

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!

like image 57
Josh Brown Avatar answered Sep 23 '22 18:09

Josh Brown