【发布时间】:2021-09-22 10:51:05
【问题描述】:
在我的项目中,我在 swift 中使用了 AlamofireImage。现在我们用 KingFisher 库替换了 AlamofireImage。我已经使用下面创建了一个结构来适应过滤器
struct AspectScaledToFitAndCenterSizeFilter: ImageFilter, Sizable {
/// The size of the filter.
let size: CGSize
/// Initializes the `AspectScaledToFitSizeFilter` instance with the given size.
///
/// - parameter size: The size.
///
/// - returns: The new `AspectScaledToFitSizeFilter` instance.
init(size: CGSize) {
self.size = size
}
/// The filter closure used to create the modified representation of the given image.
var filter: (UIImage) -> UIImage {
{ image in
image.imageAspectScaledAndCenter(toFit: self.size)
}
}
}
当我们使用 AlmofireImage 时,使用下面的代码来设置图片 url
imageView.af.setImage(withURL: imageURL.mediaURL(), placeholderImage: #imageLiteral(resourceName: "icMissingEntreeGrid"), filter: AspectScaledToFitAndCenterSizeFilter(size: imageSize))
现在我将代码替换为
imageView.kf.setImage(with: imageURL.mediaURL(), placeholder: imageLiteral(resourceName: "icMissingEntreeGrid"))
但是如何使用 KingFisher 库添加“AspectScaledToFitAndCenterSizeFilter(size: imageSize)”。任何人都可以在这里帮助我。提前致谢。
【问题讨论】:
标签: ios swift alamofireimage kingfisher