Iphone modal dialogue, like a native "take a picture, choose existing"

How to create a modal dialog with custom buttons, like "take a picture or video" | "select an existing" dialog on iPhone? These buttons are not regular UIButton, and I am sure that they are not manually created for each application.

+6
source share
1 answer

It looks like you want to use a combination of UIActionSheet and UIImagePickerController. This code shows a popup that allows the user to select a photo or select an existing one, then the UIImagePickerController will pretty much do the rest:

- (IBAction)handleUploadPhotoTouch:(id)sender { mediaPicker = [[UIImagePickerController alloc] init]; [mediaPicker setDelegate:self]; mediaPicker.allowsEditing = YES; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take photo", @"Choose Existing", nil]; [actionSheet showInView:self.view]; } else { mediaPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentModalViewController:mediaPicker animated:YES]; } } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { mediaPicker.sourceType = UIImagePickerControllerSourceTypeCamera; } else if (buttonIndex == 1) { mediaPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; } [self presentModalViewController:mediaPicker animated:YES]; [actionSheet release]; } 

NOTE. It is assumed that you have a member variable "mediaPicker" that contains a reference to UIImagePickerController

+15
source

Source: https://habr.com/ru/post/886355/


All Articles