-1

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.

Harun Sagar
  • 63
  • 1
  • 8

3 Answers3

2

you have to use UIImagepicker .

Vignesh
  • 10,205
  • 2
  • 35
  • 73
2

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/

Manish Agrawal
  • 10,958
  • 6
  • 44
  • 76
1

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;
}
yas375
  • 3,940
  • 1
  • 24
  • 33