我有200像素X 200像素UIImageView
上UICollectionViewCell
,将显示来自URL的图像。问题是我不知道URL提供的分辨率图像,UIImageView
由于内存消耗,我认为最好先调整大小后再放入。
我已经使用alamofire下载图片
let url = NSURL(string: "http:\(product.picUrl)")
self.imgProductItem.af_setImageWithURL(url!, placeholderImage: UIImage(named: "app_default-resize"))
我想知道是否有任何方法可以在放置之前先调整大小UIImageView
?并且,如果有下载图像以节省内存使用量的提示,我想听听。
任何帮助,将不胜感激。谢谢你。
您可以使用过滤器:
let url = URL(string: ...)!
let placeholder = UIImage(named: "app_default-resize")
let filter = AspectScaledToFillSizeFilter(size: imageView.frame.size)
imageView.af.setImage(withURL: url, placeholderImage: placeholder, filter: filter)
参见https://github.com/Alamofire/AlamofireImage#image-filters-1。
对于Swift 2版本,请参见此答案的先前版本。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句