YNImageAsync 1.1.0

YNImageAsync 1.1.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最新发布2016年10月
SwiftSwift版本3.0
SPM支持SPM

Iurii Nechaev 维护。



  • Yury Nechaev

YNImageAsync

关于

YNImageAsync 是一个轻量级且方便的用于获取和缓存图像的框架。

功能

  • 基于 Swift 3.0 编写
  • 异步图像加载
  • 快速
  • 支持内存和磁盘缓存
  • 可配置
  • 单元测试覆盖率良好
  • 提供 UIImageView 扩展,可用于快速和即插即用的图像加载。

安装

如何

使用 URL 设置 UIImageview 的图像

if let url = URL(string: "https://upload.wikimedia.org/wikipedia/en/5/5f/Original_Doge_meme.jpg") {
    imageView.setImageWithUrl(url)
}

取消 UIImageview 的之前加载操作

imageView.cancelPreviousLoading()

直接访问缓存

// Initialize cache with 30 Mb memory capacity and disk caching
let cacheProvider = CacheProvider(configuration: CacheConfiguration(options: [.memory, .disk], memoryCacheLimit: 30 * 1024 * 1024)) 

// Save cache to memory and disk
cacheProvider.cacheData("key", data) 

// Get cached data for key
provider.cacheForKey(image, completion: { (data) in
    if let cacheData = data {
        print("Cache hit")
    } else {
        print("Cache miss")
    }
})

更改内存缓存容量

要更改最大内存缓存容量,您不需要初始化新的缓存提供程序实例。

// New memory capacity is 10 Mb
let newLimit: Int64 = 10 * 1024 * 1024        
provider.configuration.memoryCacheLimit = newLimit
// Perform memory clean operation if capacity was reduced
provider.cleanMemoryCache()

配置存储类型

您可以在初始化期间以及运行时轻松配置存储。

provider.configuration.options = .memory