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

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

  • 相关阅读:
    React 进修之路(1)
    requireJS的配置心得
    DOM的内部插入和外部插入
    h5移动端设备像素比dpr介绍
    原生js--事件类型
    React 进修之路(3)
    javaScript
    html&css
    MyBatis
    Maven基础
  • 原文地址:https://www.cnblogs.com/weicyNo-1/p/7405968.html
Copyright © 2020-2023  润新知