change UIControlState from UIControlStateSelected
to UIControlStateHighlighted
. If you want to change the background image highlighted. You need to change the UIControlState.
The following is the code snippet i test. it works.
self.addButton = [[UIBarButtonItem alloc] initWithTitle:@"hello" style:UIBarButtonItemStylePlain target:self action:@selector(addAlert:)];
[self.addButton setBackgroundImage:[UIImage imageNamed:@"font_minus_32.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self.addButton setBackgroundImage:[UIImage imageNamed:@"font_plus_32.png"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
self.navigationItem.rightBarButtonItem = self.addButton;
Also maybe the following code is the code you wanted.
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setBackgroundImage:[UIImage imageNamed:@"font_minus_32.png"] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:@"font_plus_32.png"] forState:UIControlStateHighlighted];
[btn addTarget:self action:@selector(addAlert:) forControlEvents:UIControlEventTouchUpInside];
[btn sizeToFit];
self.addButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.rightBarButtonItem = self.addButton;