SDWebImage混编
AlamofireImage
Kingfisher
TO
GitHub:https://github.com/SDWebImage/SDWebImage
cocoaPods
pod 'SDWebImage'
// 图片加载
let picPath = "https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=677762285,3327576538&fm=26&gp=0.jpg";
let picURL = NSURL(string: picPath);
SDWebImageManager.shared.loadImage(with: picURL as URL?, options: SDWebImageOptions.highPriority, progress: { (receivedSize:Int,expectedSize:Int,targetURL:URL?) in
}, completed:{ (image, data, error, SDImageCacheType, result, url) in
view1.image = image;
// 下载图片后不会将图片缓存到沙盒,需要手动调用SDImageCache.shared.store保存到沙盒
SDImageCache.shared.store(image, forKey: url?.absoluteString, completion: {
print("图片保存成功");
})
})
GitHub:https://github.com/Alamofire/AlamofireImage
cocoaPods
pod 'AlamofireImage'
// 图片加载
let picPath = "https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=677762285,3327576538&fm=26&gp=0.jpg";
guard let picURL: URL = URL(string: picPath) else {
view2.image = UIImage(named: "lty.jpg");
return;
}
//view3.af.setImage(withURL: picURL);
let serializer = ImageResponseSerializer();
let placeholderImage = UIImage(named: "lty.jpg");
let filter = AspectScaledToFillSizeWithRoundedCornersFilter(
size: CGSize(width: 100, height: 120),
radius: 10.0
)
view3.af.setImage(withURL: picURL, cacheKey: nil,
placeholderImage: placeholderImage,
serializer: serializer,
filter: filter,
progress: { progress in
}, progressQueue: DispatchQueue.main, imageTransition: .crossDissolve(0.2), runImageTransitionIfCached: true) { response in
}
GitHub:https://github.com/onevcat/Kingfisher
cocoaPods
pod 'Kingfisher'
// 图片加载
let picPath = "https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=677762285,3327576538&fm=26&gp=0.jpg";
guard let picURL: URL = URL(string: picPath) else {
view2.image = UIImage(named: "lty.jpg");
return;
}
//view2.kf.setImage(with: picURL);
let option:[KingfisherOptionsInfoItem] = [
.scaleFactor(UIScreen.main.scale),
.transition(.fade(1)),
.cacheOriginalImage
];
view2.kf.setImage(with: picURL, placeholder: UIImage(named: "lty.jpg"), options: option, progressBlock: { (receivedSize, totalSize) in
}) { Result in
print(Result);
}
AlamofireImage 使用 - swift加载网络图片,缩放图片,生成圆形图片:https://segmentfault.com/a/1190000012975482
Swift 通过URL加载图片:https://www.jianshu.com/p/f2ebb7eabe70
swift 图片加载框架 Kingfisher:https://www.jianshu.com/p/c50d31ef38d1