Skip to content
rpinto edited this page Feb 17, 2014 · 3 revisions

ImagePicker is a class used to simplify the picking image process when you develop a content creation or update page. It allows Camera and gallery native iOS image picking. The perfect example is a profile creation page where the user can select an avatar picture.

ImagePicker is based on the composition concept inspired by Unity component. Each times you need an image picking you can implement this piece of code. ImagePicker is a member variable allocated when the page appear. First declare the ImagePicker var.

@property (retain, nonatomic) ImagePicker* mAvatar;

Then allocate the object.

mAvatar = [[ImagePicker alloc] init];
mAvatar.mDelegate = self;

/!\ Don't forget to release it into the dealloc methods.

After that, when you want to pick an image call pickImage function. It will display an UIActionSheet allowing to pick an image from the camera, the device picture gallery, or if the users already pick a picture, delete it.

When the image is picked, the ImagePicker store the selected image into a member variable : mImage.

Finally, when you want to use this picked image (to send it to a web service, display it or store it on the device memory), use the mImage variable :

mImageView.image = mAvatar.mImage;

Clone this wiki locally