UIBarButtonItemStyleDone background image using th

2019-03-28 06:04发布

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.

2条回答
Viruses.
2楼-- · 2019-03-28 06:34

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

查看更多
迷人小祖宗
3楼-- · 2019-03-28 06:55

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];
}
查看更多
登录 后发表回答