How to display a UIImage from an NSURL

- by

If you’re displaying images from the main iOS bundle, things are fairly straightforward:

self.imageView.image = [UIImage imageNamed:@"Amy.png"];

But if you have an NSURL to your image then it’s not as easy. It took me some digging to find out that you have to convert the URL into NSData first, and then display the data:

NSData *imageData = [NSData dataWithContentsOfURL:destinationURL];
self.imageView.image = [UIImage imageWithData:imageData];

Convoluted – but currently the only way I know how to do it.



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.