转载请注明出处!!!

1.oc版

self.bottomButton = [UIButton buttonWithType:UIButtonTypeCustom];

self.bottomButton.frame = CGRectMake(10, [UIScreen mainScreen].bounds.size.height-70, 50, 50);

UIImage *image = [UIImage animatedImageNamed:@"aa" duration:3];

[self.bottomButton setImage:image forState:UIControlStateNormal];

[self.view addSubview:self.bottomButton];

2.swift版

var image = UIImage.animatedImageNamed("aa", duration: 3.0)  

let btn1 = UIButton.buttonWithType(UIButtonType.System) as! UIButton  

btn1.frame = CGRectMake(20, 50, 320, 36);  

btn1.setImage(image, forState: UIControlState.Normal)  

self.view.addSubview(btn1);  

 

重点是红色的部分。新建image的时候我们给了一个参数 “aa”为图片的前缀

我们只需要在工程中放入一组动画图片,命名规则为aa0  aa1  aa2 aa3。这样名称的图片就会自动被识别,并循环播放

iOS UIUIButton设置动态图片

这是我们就可以运行看到效果了。

相关文章:

  • 2022-12-23
  • 2021-04-01
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-10-24
  • 2021-10-30
  • 2021-11-12
相关资源
相似解决方案