I'm trying to setup a different image (highlighted) when the user press the UIBarButtomItem with this code:
self.addButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"addButton"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(addAlert:)];
[self.addButton setBackgroundImage:[UIImage imageNamed:@"addButtonHigh"]
forState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];
self.navigationItem.rightBarButtonItem = self.addButton;
But it is not working.
The button appears with the "addButton" image, but when it is pressed the "addButtonHigh" image doesn't appear.
Thank you in advance, Victor
change UIControlState from
UIControlStateSelectedtoUIControlStateHighlighted. 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.
Also maybe the following code is the code you wanted.