Swift 寫成的 UIImageView 的擴展:DPImageCache
DPImageCache 是 Swift 寫成的 UIImageView 的擴展,能夠異步加載圖片然后緩存至本地文件。
Features
- Load image asynchronously.
- Cache local file-based.
How to use
-
Import DPImageCache.swift
-
Set default cache directory like this:
let dirName = "cache" func createCacheDirectory() { var fileMan = NSFileManager.defaultManager() var 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:
var imgAddress = "http://blabla.com/blabla.png" imgView.setImageCacheWithAddress( imgAddress, placeHolderImage: UIImage(named: "placeHolderImage")!, cacheDirName: dirName)
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!