Drop in replacement for downloading UIImages asynchronously
- Swift 3
- iOS 10 or Later
- Developed in XCode 8
Drag AsynImageView.Swift to your project.
Image can be asynchronously loaded in three different ways using AsyncImageView
Load image from URL
let aImageView = AsyncImageView(frame: "YOUR_IMAGEVIEW_FRAME")
aImageView.imageURL = URL(string: "YOUR_IMAGE_URL")
self.view.addSubView(aImageView)
Load image directly from string. This is just a convinience.
let aImageView = AsyncImageView(frame: "YOUR_IMAGEVIEW_FRAME")
aImageView.imageURLString = "YOUR_IMAGE_URL_STRING"
self.view.addSubView(aImageView)
Load image using completion handler. This usage is helpful if you need to load images asynchronously without subclassing UIImageView from AsyncImageView. For example, UIButton's imageView can be loaded asynchronously with this usage without requiring any subclassing of AsyncImageView.
let button = UIButton(type: .custom)
button.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
button.loadImageAsync(fromURL: URL(string: "YOUR_IMAGE_URL")!, for: .normal)
self.view.addSubview(button)
or simply
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
imageView.loadImageAsync(fromURL: URL(string: "YOUR_IMAGE_URL")!)
self.view.addSubview(imageView)