我正在使用Kingfisher库,但我的问题是,我不能将这个库用于存储在assets中的图片--所有的kingfisher方法都需要url,所以我如何将这个库用于assets?
那些在评论中说我们不需要通过kingfisher从assets中加载本地图片的人,有一种情况,比如我们在UITableView中加载图片,在if条件下,我们从远程URL加载图片,在else条件下,我们从本地assets加载图片。在这种情况下,如果我们直接将一个图片以 UIImage(...)
方法,TableView的图片会开始出现异常。所以我们需要通知Kingfisher,我们直接修改了图片,当图片从远程URL加载时,不要更新。
import Kingfisher
//////// In your cellForRowAt method
if (loadThroughRemoteURL) {
cell.imageView.kf.setImage(with: URL(string: "YOUR_REMOTE_IMAGE_URL"))
}
else { // loading through local assets
let resource: Resource? = nil
cell.imageView.kf.setImage(with: resource) // inform kingfisher that you are assigning this image by your own
cell.imageView.image = UIImage(named: "your_image_in_assets")
}