美文网首页
iOS UIUIButton设置动态图片

iOS UIUIButton设置动态图片

作者: weicyNO_1 | 来源:发表于2017-10-08 18:57 被阅读0次

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设置动态图片

      本文链接:https://www.haomeiwen.com/subject/lwlyyxtx.html