AAsyncImageLoader 0.1.1

AAsyncImageLoader 0.1.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2016年6月
SPM支持 SPM

Jérôme Gx 维护。



  • 作者
  • Jérôme Gx

AAsyncImageLoader

一个异步图像加载器,包含一些魔法,包括用于上手集成的 UIImageView 分类。

这个库将允许您通过 UIImageView 分类从网络加载图像。

它也是一个更强大的低级加载库,可以从互联网获取 UIImage,允许您控制您想要放置的逻辑。

如何使用它

要求
这个库需要 iOS7,不需要其他任何东西 :)
您可以从中 Tempo 安装(请参阅安装)

然后 import AAsyncImageLoader

单行代码

如果您需要直接集成的版本,它的操作非常简单

imageView.aail_load(NSURL(string: "https://example.com/image.jpg")!, placeholder: UIImage(named: "placeholder_image"))

可重复使用的单元

这个库包含一些魔法,并且会对您的可重复使用单元工作得非常好。
它具有内置的取消机制

// example from the demo app
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let CellIdentifier = "Cell"
    let cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier, forIndexPath: indexPath)

    let name = Array<String>(data.keys)[indexPath.row]
    let imageUrl = data[name]!

    cell.textLabel?.text = name
    cell.imageView?.aail_load(NSURL(string: imageUrl)!, placeholder: UIImage(named: "placeholder_image"))

    return cell
}

控制权

您也可以通过使用库的核心来获取更多控制,例如调整配置选项(如缓存)或取消请求

var myImage = UIImage()

let configuration = AAsyncImageLoaderConfiguration()
configuration.defineCachePolicy(.ForceReload)

let aasyncRequest = AAsyncImageLoader(configuration: configuration)
aasyncRequest.withUrl(NSURL(string: "https://example.com/image.jpg")!) {
    image, error in
    if let image = image {
        myImage = image
        // maybe do something with this image
        // don't forget to get back on the main thread
    } else {
        // do something with the error
    }
}
.load() // start the request

// later in the code you can cancel the request if needed
aasyncRequest.cancel()

示例项目

要运行示例项目,请克隆存储库,然后首先从 Example 目录中运行 pod install

测试

这个库包含单元测试,您可以通过在 XCode 中检出此存储库并从中运行来启动它们

安装

手动

如有必要,您还可以将 AAsyncImageLoader* 文件复制/粘贴到您的应用程序中

贡献

AAsyncImageLoader 是一个开源项目。如果您想贡献,请提交拉取请求。
但您不必编写代码,您还可以

  • 报告错误
  • 提问
  • 编写更多示例或文档
  • 提出新想法

如果您发现错误并愿意修复它,我们将检查您的拉取请求,并在相关的情况下整合它

许可证

AAsyncImageLoader可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。