iOS UIUIButton设置动态图片

转载请注明出处!!!

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。这样名称的图片就会自动被识别,并循环播放

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

转载于:https://www.cnblogs.com/weicyNo-1/p/7405968.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值