Animated Images in a UIButton

后端 未结 1 898
别那么骄傲
别那么骄傲 2020-12-29 06:13

What is the best way to animate images of a button?

Say I want to cycle through like 6 frames and have the user still be able to click the button?

Should I a

相关标签:
1条回答
  • 2020-12-29 06:58

    You can do this using the imageView property of UIButton. This will allow the button to behave as it normally would with your images animating on it. Here's an example:

    NSMutableArray *imageArray = [NSMutableArray new];
    
    for (int i = 1; i < 4; i ++) {
        [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i]]];
    }
    
    [myButton setImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
    
    [myButton.imageView setAnimationImages:[imageArray copy]];
    [myButton.imageView setAnimationDuration:0.5];
    
    [myButton.imageView startAnimating];
    
    0 讨论(0)
提交回复
热议问题