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
UIControlStateHighlighted Highlighted state of a control. A control enters this state when a touch enters and exits during tracking and when there is a touch up event. You can retrieve and set this value through the highlighted property.
UIControlStateSelected Selected state of a control. For many controls, this state has no effect on behavior or appearance. But other subclasses (for example, the UISegmentedControl class) may have different appearance depending on their selected state. You can retrieve and set this value through the selected property.