swift add animated icon code example

Example: swift add animated icon

func createImageArray(total: Int, imagePrefix: String) -> [UIImage] {
    var imageArray:[UIImage] = []
    for imageCount in 1..<total {
        let imageName = "\(imagePrefix).\(imageCount)"
        let image = UIImage(named: imageName)!

        imageArray.append(image)
    }

    return imageArray
}

func animate(imageView: UIImageView, images: [UIImage]) {
    imageView.animationImages = images
    imageView.animationDuration = 0.7
    imageView.animationRepeatCount = 1
    imageView.startAnimating()
}

Tags: