Last active
February 28, 2019 10:32
-
-
Save shreyakupadhyay/e3f8fcde4a71a5f6f6c9c4245b57895f to your computer and use it in GitHub Desktop.
Implement an ImageView Programmatically in Swift with Synchronous fetching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
var imageView: UIImageView! | |
let urlImageView = "https://scontent.fblr1-4.fna.fbcdn.net/v/t1.0-9/41680104_2150992674919611_3587931360280444928_n.jpg?_nc_cat=110&_nc_ht=scontent.fblr1-4.fna&oh=0ade5c5fe8c8b5f476fa8336b25fc72f&oe=5CE5D475" | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
addImagesToView() | |
} | |
func addImagesToView(){ | |
let imageUrl:URL = URL(string: urlImageView)! | |
let imageData:NSData = NSData(contentsOf: imageUrl)! | |
let imageView = UIImageView(frame: CGRect(x:0, y:0, width:200, height:200)) | |
let image = UIImage(data: imageData as Data) | |
imageView.image = image | |
self.view.addSubview(imageView) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment