UIToolbar tint on iOS 4

Oded Ben Dov picture Oded Ben Dov · Jun 30, 2010 · Viewed 18.6k times · Source

just switched to iOS 4 on my iPhone 3GS and some of my apps broke.

One issue I had is that I had a UIToolbar with some buttons, tinted to pink, that worked well on the 3.1.3 OS. After upgrading to iOS 4, the toolbar was still tinted, but the buttons it contained were no longer affected by the tint. The toolbar was pink while the buttons were regular-blue.

Looked around for it on the net, but found no reference of such a thing.

Anyone knows what broke in the process?

Answer

Oded Ben Dov picture Oded Ben Dov · Jun 30, 2010

(must be frank here - I knew the answer before posting, just didn't know how to load this data to StackOverflow. Thought the solution I found was valuable for others, so wanted to post it here. I'm new here, so please no harsh critics :) )

So eventually the problem resulted from, AFAICT, a change in behavior in the OS.

As stated the tint code worked before the upgrade and was written like this:

// Toolbar content               
NSArray *items=[NSArray arrayWithObjects: ... ]; // PSEUDO CODE HERE
[toolbar setItems:items]; 

// Add tint
toolbar.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];

What I needed to do, was just reverse the order of things:

// Add tint
toolbar.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];

// Toolbar content               
NSArray *items=[NSArray arrayWithObjects: ... ]; // PSEUDO CODE HERE
[toolbar setItems:items]; 

(If you created UIToolbar in Interface Builder, you can change it's tint there, and that applies for the buttons as well).

I guess the tint updated all buttons before iOS 4, while in iOS 4 it doesn't and when adding buttons, they check for existing tint. But this is just a guess. The solution works anyhow..

Hope this helps someone, and that I didn't violate any sacred SO rules...

Cheers!