iOS 基础控件 UIImageView
1. UIImageView 的使用
let uiImage = UIImage(named: "demo")
let size = uiImage?.size
print(size?.width.description as Any, size?.height.description as Any)
let imageView = UIImageView(image: uiImage)
imageView.frame = CGRect(x: 30, y: 460, width: 80, height: 80)
self.view.addSubview(imageView)
效果展示:
2. UIImageView 播放桢动画
var imageArray = Array<UIImage>()
for index in 1...15 {
let uiImage = UIImage(named: "shark\(index)")
imageArray.append(uiImage!)
}
let imageView = UIImageView(frame: CGRect(x: 150, y: 460, width: 80, height: 80))
imageView.animationImages = imageArray
imageView.animationDuration = 3
imageView.animationRepeatCount = 0
self.view.addSubview(imageView)
imageView.startAnimating()
效果展示:
附 Github 源码:
ViewController.swift
|