6

How can I provide a visually distinct bar button item background image for bar buttons with the UIBarButtonItemStyleDone style and the editing state of the Edit/Done button? None of the documented UIControlState values in the UIBarButtonItem appearance proxy's setBackgroundImage:forState:barMetrics: seem to do the trick.

  • Are you trying to customize the appearance of the buttons specifically or would you like a similar background for all UIBarButtons? – sean woodward Jan 04 '12 at 21:26
  • I second that question. Could only set one backgroundImage for [UIBarButtonItem appearance], but can't find how to set a different image for "Done" button. If I try to setBackgroundImage of the Done button's instance, it changes back to the default appearance. I don't get it. – Kof Jan 13 '12 at 03:44

2 Answers2

1

I'm not sure why this was never answered but if you are still looking then simply create a property for a BarButtonItem in your .h, assign it in IB, then set the background property of that barButtonItem. Works fine for me and never "changes back to default appearance".

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.barButton setBackgroundImage:[UIImage imageNamed:@"YOURIMAGE"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
0

I have just found and posted a possible solution to this problem. You can 'inject' custom styles using a UIBarButtonItem category:

Customizing UIBarButtonItem "Done" style and "Plain" style separately using UIAppearance

Community
  • 1
  • 1
Molotoff
  • 553
  • 5
  • 7