Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItemStyleDone background image using the iOS 5 appearance API

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.

like image 767
Jukka Partanen Avatar asked Nov 21 '11 11:11

Jukka Partanen


1 Answers

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];
}
like image 145
Mark McCorkle Avatar answered Nov 04 '22 21:11

Mark McCorkle