How to change the color of UIBarButtonItem on iOS 5

My most popular blog post is how to change the color of a UIBarButtonItem. It’s something that lots of people want to do, but it involved some pretty weird hacks to get it working.

Now that iOS 5 is out, I can talk about a better way to do it. Apple will now let you set the tintColor: property on the bar button item. That’s it. No more weird hacks with images or segmented controls.

There’s even a cool new appearance proxy that will let you change all controls from your app with a single line of code. (More about UIAppearance here)

So lets say you want every UIBarButtonItem in your application to be blue. That’s easy just call [UIBarButtonItem appearance] setTintColor:[UIColor blueColor]]

Remember, this is iOS 5 only. If you want your app to support iOS 4, you’ll have to do it the old way.

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

2 Responses to How to change the color of UIBarButtonItem on iOS 5

  1. Pingback: How to change the color of a UIBarButtonItem | farp.blog

  2. Morgan says:

    Hi Hi,

    If you want the blue to be exactly the same at the “done” button you gotta do the following:

    I spent about 15 mins with my DigitalColor Meter and basically guessed and checked until I finally got it. The problem is that you’re adding a “tint” to a black button to make it blue, so it won’t be the right blue. Here’s the correct measurements:

    [buttonName setTintColor:[UIColor colorWithRed:34.0/255.0 green:97.0/255.0 blue:221.0/255.0 alpha:1]];

    Hope it helps someone :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>