iOS - Swift -UIimageView

Posted zsjxxy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS - Swift -UIimageView相关的知识,希望对你有一定的参考价值。

//

//  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.

    }

    */

 

}

 

以上是关于iOS - Swift -UIimageView的主要内容,如果未能解决你的问题,请参考以下文章

iOS开发中OC和swift的对比

ios OC、swift混编制作framework

iOS-swift-基础篇1

iOS开发系列--Swift 3.0

swift 2016年 - iOS / PlayerViewController.swift

swift iOS URL Schemes Swift