Tag Archives: UIImage

How to display a UIImage from an NSURL

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

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:

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

How to select a UIImage from the camera roll (and use it)

The UIImagePickerController can help us do this with ease.

In this example we’ll instantiate it, then we tell it what kind of image we want returned (we’re using an edited version here, but we could just as well return the original, or start using a camera). Next we present a modal view controller where the actual image selection takes place:

For this to work you need to conform to the UIImagePickerControllerDelegate protocol, as well as the UINavigationControllerDelegate (the latter does not need any methods – it’s just so that the warning to myPicker.delegate = self goes away really).

The two methods we need from the first protocol are to deal with a selection and a cancellation. In this example I’m displaying the returned image in a UIImageView:

How to load a UIImage that we’ve previously saved

How to save a UIImage