views:

9898

answers:

5

Is it possible to have a red UIBarButtonItem?

A: 

You can create a custom image for the button and use that. Else, if you have set the tintColor of your navbar or toolbar to red, the button items on these will also appear red.

lostInTransit
+2  A: 

Using a custom image doesn't work as it just uses the alpha to render the button.

leftspin
+9  A: 

You can create custom UIButton with your desired look and initialize your UIBarButtonItem with it as a custom view.

UIButton *button = [UIButton buttonWithType:....];
...(customize your button)...

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
Marcus Foster
+2  A: 

see http://www.iphonedevsdk.com/forum/iphone-sdk-development/33286-color-image-uibarbuttonitem-uitoolbar.html which helped me...

Steve
Good link - the big post in there has the good info. I was trying to create a UIBarButtonItem with a UIImageView as the customView. The better way to do it, as described in that post, is to create a UIButton for the customView instead. In my case I also needed to change the image based on the state of the data (whether the data was a favorite item or not) so I also set an image for the button's "UIControlStateSelected" state, then toggled it as needed:[(UIButton *)self.favBarButtonItem.customView setSelected:isFavorited];Sure wish the SDK made this more straightforward!
Jason
A: 

If using IB (Interface Builder), drag a UIView from the Library onto the UIToolBar, and it will generate a UIBarButtonItem with a custom view. You can then add any other controls you want to it, e.g. UIButton, UILabel, UIActivityIndicatorView.

apalopohapa