aimak / DPImageCache

Swift extension for UIImageView. Help loading image asynchronously and store local file cache.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DPImageCache

Swift extension for UIImageView. Help loading image asynchronously and store local file cache.

Features

  • Load image asynchronously.
  • Cache local file-based.

alt tag

How to use

  • 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)

Contact

www: http://dinophan.com email: baophan94@icloud.com

About

Swift extension for UIImageView. Help loading image asynchronously and store local file cache.


Languages

Language:Swift 100.0%