DiscussionIPhoneMobile phonePhotographFunctions and photosCredits LibrarySelecting function call is the content to be introduced in this article. There is not much content, mainly through code implementation. Let's look at the content.
First, you must implement UIImagePickerControllerDelegate and UINavigationControllerDelegate.
Next, define the button:
- // Upload one from the album
- UIButton * btn1 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
- Btn1.frame = CGRectMake (60.0, 237.0, 200.0, 32.0 );
- [Btn1 setTitle: @ "selecting images from the media repository" forState: UIControlStateNormal];
- [Btn1 addTarget: self action: @ selector (picker) forControlEvents: UIControlEventTouchUpInside];
- UIButton * btn2 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
- Btn2.frame = CGRectMake (60.0, 290.0, 200.0, 32.0 );
- [Btn2 setTitle: @ "get image from camera" forState: UIControlStateNormal];
- [Btn2 addTarget: self action: @ selector (picker1) forControlEvents: UIControlEventTouchUpInside];
Button implementation method:
- // Select from the Photo Library
-
- -(Void) picker
-
- {
-
- Imagepicker = [[UIImagePickerController alloc] init];
-
- Imagepicker. delegate = self;
-
- Imagepicker. sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- Imagepicker. modalTransitionStyle = UIModalTransitionStyleCoverVertical;
- Imagepicker. allowsEditing = YES;
- [Self presentModalViewController: self. imagepicker animated: YES];
- }
- // Obtain from the camera
- -(Void) picker1
- {
- Imagepicker = [[UIImagePickerController alloc] init];
- Imagepicker. delegate = self;
- Imagepicker. sourceType = UIImagePickerControllerSourceTypeCamera;
- Imagepicker. modalTransitionStyle = UIModalTransitionStyleCoverVertical;
- Imagepicker. allowsEditing = YES;
- [Self presentModalViewController: self. imagepicker animated: YES];
- }
Proxy method:
- // Initialize and select
- -(Void) imagePickerController :( UIImagePickerController *) picker
- DidFinishPickingImage :( UIImage *) image
- EditingInfo :( NSDictionary *) editingInfo
- {
- MyImageView. image = image;
- [[Picker parentViewController] dismissModalViewControllerAnimated: YES];
- }
- // Select
-
- -(Void) imagePickerControllerDidCancel :( UIImagePickerController *) picker
- {
- [Picker dismissModalViewControllerAnimated: YES];
- }
Summary:IPhoneMobile phonePhotographFunctions andPhoto GalleryThis article is helpful to you.