I would like to create a UIButton that toggles its image. Once clicked the image should change to another one and stay that way until clicked again.
I have added both images to the default and selected states of the button on interface builder.
Now, I have created a UIButton subclass. My idea is to intercept the tap to that button and change the button state. So I added this to the UIButton subclass, hoping one of these methods would be triggered by a tap.
- (void)sendAction:(SEL)action
to:(id)target
forEvent:(UIEvent *)event {
[super sendAction:action to:target forEvent:event];
// toggle state
[self setSelected:![self isSelected]];
}
- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents {
[super sendActionsForControlEvents:controlEvents];
// toggle state
[self setSelected:![self isSelected]];
}
- (void)touchesEnded:(NSSet *)touches
withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
// toggle state
[self setSelected:![self isSelected]];
}
None of these methods are triggered. Any clues?