I have a UIButton in one of my ViewControllers with three different state images (normal, highlighted and selected). When I press this button, it becomes highlighted and when I release it, selected. I want to make an animation that changes the highlighted image of the button to the selected one in 4 seconds with a fadeIn or so.
Any suggestion?
Try UIView transitionWithView by setting first the normal and selected images to UIButton, and then in the action handler animate the change:
[UIView transitionWithView:self.addListButton
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.addListButton setSelected:YES];
} completion:nil];
I didn't want to change the state of the UIButton so I just changed the normal image in the animation block:
[self.addListButton setImage:[UIImage imageNamed:@"icon-addbutton.png"]
forState:UIControlStateNormal];
You have to enroll your own UIButton subclass and you'll probably have to overwrite setSelected and setHighlighted with your custom animation code. The safer bet would be to subclass UIControl directly and reimplement those selectors so that you don't have any UIButton specific legacy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With