Skip to content

Instantly share code, notes, and snippets.

@SwiftArchitect
Created February 19, 2016 16:05
Show Gist options
  • Save SwiftArchitect/2d2e1c42599dfb519509 to your computer and use it in GitHub Desktop.
Save SwiftArchitect/2d2e1c42599dfb519509 to your computer and use it in GitHub Desktop.
Loads a set of UIImage named "win_1" to "win_16" from Assets catalog and animate in a UIImageView
//
// ViewController.swift
// SO-35412222
//
// Copyright © 2016 Xavier Schott
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
var images = [UIImage]();
for i in 1...16 {
let imageName = "win_\(i)"
guard let image = UIImage(named: imageName) else {
print("\(imageName) not found")
continue
}
images.append(image)
}
imageView.animationImages = images
imageView.animationDuration = 1
imageView.startAnimating()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment