Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Swift Tips for Loading Image Faster

Tags:

ios

image

swift

png

I have PNG images that range from 2MB to 12MB in size. I'm loading one of these images into an imageView using SDWebImage via the following code in my viewDidLoad:

self.imageView.contentMode = UIViewContentMode.ScaleAspectFit
self.imageView.sd_setImageWithURL(NSURL(string: imageURL))

It can take as high as 17 seconds to load this image onto the view. Am I doing something wrong here? I'm only loading one of these images into my view, so I did not think it would take this long. Any other things I can do to load the image faster?

Is the only option creating a smaller image to load?

like image 782
JK140 Avatar asked Dec 05 '25 10:12

JK140


1 Answers

If you are trying to download a thumbnail image from the back-end you can try adding the context parameter in your SDWebImage call.

yourImageView.sd_setImageWithURL(withPlaceholder: nil, context: [.imageThumbnailPixelSize: yourThumbnailSize])

Add some constant image thumbnail pixel size as shown above.

like image 143
iPhoneDeveloper Avatar answered Dec 07 '25 01:12

iPhoneDeveloper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!