Created
December 9, 2019 15:14
-
-
Save yoxisem544/63b2b9ca6c52f552fef703bbad273276 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// 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