How to display a UIImage from an NSURL

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.





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.