Swift extension for UIImageView. Help loading image asynchronously and store local file cache.
- Load image asynchronously.
- Cache local file-based.
-
Import DPImageCache.swift
-
Set default cache directory like this:
let dirName = "cache"
func createCacheDirectory() {
let fileMan = NSFileManager.defaultManager()
let cacheDir = (NSSearchPathForDirectoriesInDomains(
.DocumentDirectory,
.UserDomainMask, true)[0] as! NSString)
.stringByAppendingPathComponent(dirName)
if !fileMan.fileExistsAtPath(cacheDir) {
fileMan.createDirectoryAtPath(
cacheDir,
withIntermediateDirectories: false,
attributes: nil,
error: nil)
}
}
- Simple code like this:
let imgAddress = "http://blabla.com/blabla.png"
imgView.setImageCacheWithAddress(
imgAddress,
placeHolderImage: UIImage(named: "placeHolderImage")!,
cacheDirName: dirName)
www: http://dinophan.com email: baophan94@icloud.com