Skip to content

Instantly share code, notes, and snippets.

@remirobert
Created December 22, 2015 02:37
Show Gist options
  • Save remirobert/4cdb0c04e8329df03289 to your computer and use it in GitHub Desktop.
Save remirobert/4cdb0c04e8329df03289 to your computer and use it in GitHub Desktop.
import UIKit
import SnapKit
import FLAnimatedImage
class ViewController: UIViewController {
let urlImage = "http://i.giphy.com/13YkBrhLJdziXm.gif"
var aniamtedImageView: FLAnimatedImageView = {
return FLAnimatedImageView()
}()
var welcomeTextLabel: UILabel = {
let welcomeTextLabel = UILabel()
welcomeTextLabel.text = "Hello world !"
welcomeTextLabel.textAlignment = .Center
welcomeTextLabel.textColor = UIColor.whiteColor()
welcomeTextLabel.font = UIFont.systemFontOfSize(30)
return welcomeTextLabel
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.blackColor()
self.aniamtedImageView.backgroundColor = UIColor.redColor()
self.view.addSubview(self.aniamtedImageView)
self.aniamtedImageView.snp_makeConstraints { (make) -> Void in
make.size.equalTo(CGSizeMake(200, 200))
make.center.equalTo(self.view)
}
self.view.addSubview(self.welcomeTextLabel)
self.welcomeTextLabel.snp_makeConstraints { (make) -> Void in
make.centerX.equalTo(self.view)
make.height.equalTo(50)
make.bottom.equalTo(self.aniamtedImageView).offset(50)
}
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
dispatch_async(queue) { () -> Void in
if let url = NSURL(string: self.urlImage), let dataImage = NSData(contentsOfURL: url) {
let img = FLAnimatedImage(GIFData: dataImage)
dispatch_async(dispatch_get_main_queue(), {
self.aniamtedImageView.animatedImage = img
})
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment