Add selection animation to UIButton

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, it is selected. I want to make an animation that changes the selected button image to the selected one in 4 seconds using fadeIn or so.

Any suggestion?

+5
source share
2 answers

Try UIView transitionWithViewsetting the usual and selected images to first UIButton, and then change it in the event handler:

[UIView transitionWithView:self.addListButton
                  duration:0.3
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{
                    [self.addListButton setSelected:YES];
                } completion:nil];

UIButton, :

[self.addListButton setImage:[UIImage imageNamed:@"icon-addbutton.png"]
    forState:UIControlStateNormal];
+9

UIButton, , , setSelected setHighlighted . UIControl , UIButton .

+2

All Articles