Skip to content

Instantly share code, notes, and snippets.

@yoxisem544
Created December 9, 2019 15:14
Show Gist options
  • Save yoxisem544/63b2b9ca6c52f552fef703bbad273276 to your computer and use it in GitHub Desktop.
Save yoxisem544/63b2b9ca6c52f552fef703bbad273276 to your computer and use it in GitHub Desktop.
//
// UIImageView+Unsplash.swift
// Created by David on 2019/12/9.
//
import UIKit.UIImageView
import Kingfisher
/// check api doc: https://source.unsplash.com/
fileprivate let randomUnsplashImageURL = "https://source.unsplash.com/random"
public extension UIImageView {
func loadRandomUnsplashImage(width: Int, height: Int) {
let url = URL(string: "\(randomUnsplashImageURL)/\(width)x\(height)")!
loadImage(from: url)
}
func loadRandomUnsplashImage() {
loadImage(from: URL(string: randomUnsplashImageURL)!)
}
fileprivate func loadImage(from url: URL) {
ImageCache.default.removeImage(forKey: url.absoluteString)
kf.setImage(with: url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment