Sonic Master Sonic Master - 1 year ago 271
iOS Question

Resize Download Image with AlamofireImage

I have 200px x 200px

that will display an image from URL. The problem is I don't know what resolution's image provided by the URL and I think it's better to resize it first before placing in
due to memory consumption.

I already use alamofire to download an image

let url = NSURL(string: "http:\(product.picUrl)")
self.imgProductItem.af_setImageWithURL(url!, placeholderImage: UIImage(named: "app_default-resize"))

I am wondering is there any method to resize it first before it use to place in
? And if any tips for download an image to save memory usage, I'd like to hear that.

Any help would be appreciated. Thank you.

Rob Rob
Answer Source

You can use filters:

let url = NSURL(string: ...)!
let placeholder = UIImage(named: "app_default-resize")

let filter = AspectScaledToFillSizeFilter(size: imageView.frame.size)
imageView.af_setImageWithURL(url, placeholderImage: placeholder, filter: filter)


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download