func KingfisherDefaultOptionsInfoItem() -> [KingfisherOptionsInfoItem] {
return [.transition(.fade(0.2)), .keepCurrentImageWhileLoading]
}
extension UIImageView {
func setNetImgWithCornerRadius(
urlString: String,
placeholder:UIImage?,
targetSize: CGSize,
cornerRadius: CGFloat,
roundingCorners: RectCorner = .all,
backgroundColor: UIColor = .clear,
priority: Float = URLSessionTask.defaultPriority) {
var options = KingfisherDefaultOptionsInfoItem()
options.append(.downloadPriority(priority))
let resize = ResizingImageProcessor(referenceSize: targetSize, mode: .aspectFill)
let crop = CroppingImageProcessor(size: targetSize)
let round = RoundCornerImageProcessor(cornerRadius: cornerRadius, roundingCorners: roundingCorners, backgroundColor: backgroundColor)
let processor = (resize >> crop) >> round
options.append(.processor(processor))
let url = URL(string: urlString)
kf.setImage(with: url, placeholder: placeholder, options: options, progressBlock: nil, completionHandler: nil)
}
}
extension UIImageView {
func setNetImgWithBlur(urlString: String,
placeholder:UIImage?,
blurRadius: CGFloat,
tintColor: UIColor,
priority: Float = URLSessionTask.defaultPriority) {
var options = KingfisherDefaultOptionsInfoItem()
options.append(.downloadPriority(priority))
let processor = BlurImageProcessor(blurRadius: blurRadius)
let processor2 = TintImageProcessor(tint: tintColor)
options.append(.processor(processor >> processor2))
let url = URL(string: urlString)
kf.setImage(with: url,
placeholder: placeholder,
options: options,
progressBlock: nil,
completionHandler: nil)
}
}
网友评论