EDIT: There is a new way to do this in iOS 5 that is much easier and nicer. If you want to support iOS 4, keep reading.
A UIBarButtonItem is an item that goes on a UIToolbar or a UINavigationBar. It’s typically a button but it can be a bunch of different things. I’m going to talk about the button. A UIBarButtonItem button takes on the color of the bar that it is on. You can set the tint of a UIToolbar, but you can’t change the colors of the buttons on it.
I found lots of different solutions for this online, most involving adding a UIButton as the customView of the UIBarButtonItem and having some sort of image for the color you need. That works fine, until you need a color that you don’t have an image for.
I found a better solution here. Basically what they figured out was that a UISegmentedControl with a style of UISegmentedControlStyleBar looks just like a UIBarButtonItem. A key difference is that UISegmentedControl has a nice tintColor property that you can use to change the colors.
So what I did was take CharlyBr‘s code and put it into a UIBarButtonItem category.
+(UIBarButtonItem*)barButtonItemWithTint:(UIColor*)color andTitle:(NSString*)itemTitle andTarget:(id)theTarget andSelector:(SEL)selector { UISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:itemTitle, nil]] autorelease]; button.momentary = YES; button.segmentedControlStyle = UISegmentedControlStyleBar; button.tintColor = color; [button addTarget:theTarget action:selector forControlEvents:UIControlEventValueChanged]; UIBarButtonItem *removeButton = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease]; return removeButton; }
You can check out my example project on GitHub.