swift UIButton 设置动态图片

来源:互联网 发布:ar卡片制作软件 编辑:程序博客网 时间:2024/05/16 07:25

一般的gif图片大家应该不陌生,那么如何给UIButton设置一个动态的图片了

其实很简单 我们先看下代码

[objc] view plaincopy
  1. var image=UIImage.animatedImageNamed("test", duration2.0)  
  2.   
  3. let btn1=UIButton.buttonWithType(UIButtonType.System) as! UIButton  
  4. btn1.frame=CGRectMake(205032036);  
  5. btn1.setImage(image, forState: UIControlState.Normal)  
  6. self.view.addSubview(btn1);  

新建image的时候我们给了一个参数 “test”

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

好了 只要按照上边的要求实现。运行一下就能看到 button上的图片在动了















0 0
原创粉丝点击