iOS - Swift -UIimageView

时间:2022-04-28 04:59:12

//

//  ViewController.swift

//  Label

//

//  Created by 赵士军 on 2019/11/18.

//  Copyright © 2019 赵士军. All rights reserved.

//

 

import UIKit

 

class ViewController: UIViewController {

 

    override func viewDidLoad() {

        super.viewDidLoad()

  

        self.setupImageView()

    }

    func setupImageView() {

        //初始化一个imageView

        let firstImageView  = UIImageView.init(frame: self.view.frame)

        //设置imageView的图片

//        firstImageView.image = UIImage.init(named: "imagee")

         firstImageView.backgroundColor = .red

        firstImageView.contentMode = .scaleAspectFit

        //将Label添加到父self.view上来做显示

        self.view.addSubview(firstImageView)

    }

    

    func setupAnimationImageView() {

        //初始化一个imageView

        let firstImageView = UIImageView.init(frame: CGRect.init(x: 0, y: 0, width: 251, height: 375))

        //设置imageView的中心位置

        firstImageView.center = self.view.center

        //获取图片序列数组

        let imagesArray = NSMutableArray.init()

        //数组中添加Images

        for i in 1...10 {

            let image = UIImage.init(named: String.init(format: "firas%d", i))

            

            imagesArray.add(image as Any)

        }

        //设置动画数组

        firstImageView.animationImages = imagesArray as? [UIImage]

        

        //设置动画时长

        firstImageView.animationDuration = 1.2

        //设置动画播放次数,0表示无限次

        firstImageView.animationRepeatCount = 0

        //开始动画

        firstImageView.startAnimating()

        //将Label添加到父self.view上来做显示

        self.view.addSubview(firstImageView)

    }

 

    /*

    // MARK: - Navigation

 

    // In a storyboard-based application, you will often want to do a little preparation before navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        // Get the new view controller using segue.destination.

        // Pass the selected object to the new view controller.

    }

    */

 

}