Get Photo from iPhone Photo library
-
08-12-2019 - |
Question
I have create an iPhone application. I have a button in a view. In the button click i want to get the photo from iPhone photo library. And set this selected photo in the button. How can i do that. thanks in advance.
Solution
you can follow this tutorial to get image from phone galley or from camera. http://www.icodeblog.com/2009/07/28/getting-images-from-the-iphone-photo-library-or-camera-using-uiimagepickercontroller/
OTHER TIPS
you have to use UIImagepicker .
A few days ago I do something like this for ipad.
Let call your button photoButton
and it's a variable in our controller. Also add popoverController
variable (it's needed to appropriate dismiss of popover).
When photoButton pressed we call next method:
- (void)photoButtonPressed:(id)sender {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = NO;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popoverController.delegate = self;
[popoverController presentPopoverFromRect:sender
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[imagePickerController release];
}
Also you should implement next methods to support UIImagePickerControllerDelegate and UIPopoverControllerDelegate protocol:
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)selectedImage
editingInfo:(NSDictionary *)editingInfo {
[photoButton setImage:selectedImage forState:UIControlStateNormal];
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
}
#pragma mark - UIPopoverControllerDelegate
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverContr {
[popoverContr release];
if (popoverContr == popoverController)
popoverController = nil;
}