views:

311

answers:

1

Hi,

I want to customize a UIBarButtonItem's background. Here's the code I use:

UIButton *button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[button setBackgroundImage:[UIImage imageNamed:@"ButtonBackground.png"] forState:UIControlStateNormal];
[editButton setCustomView:button]; // editButton is the UIBarButtonItem

Unfortunately, this doesn't work. Instead of showing the UIBarButtonItem, it simply vanishes (it becomes 100% transparent). When I leave out the setCustomView method, the UIBarButtonItem appears, but is not customized.

How can I solve this problem?

Thanks!

Rich

A: 

You should try to set the UIButton's frame property to something reasonable, e.g. add a

button.frame = CGRectMake(0, 0, 60, 40);
MrMage