如何在UIImagePickerController popover中添加自定义按钮

时间:2017-01-04 09:10:20

标签: objective-c xamarin.ios

gist.github.com当我从图库中选择图片时,如何在UIImagePickerController popover中添加自定义按钮?

1 个答案:

答案 0 :(得分:0)

知道了。这些是Apple为UIImagePickerViewController提供的默认按钮。因此,您必须使用一个属性,属性为YES。您必须将其设置为-(void)openGallery { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = YES; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:picker animated:YES completion:NULL]; } -(void)openCamera { BOOL isCameraPresent = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; if(isCameraPresent) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = YES; picker.sourceType = UIImagePickerControllerSourceTypeCamera; // Add overlay view with custom button on it. Set frames to button as per your choice. UIView *viewOverlay = [[UIView alloc]initWithFrame:self.view.bounds]; Create and initialise your `UIButton` here [viewOverlay addSubview:YOUR_BUTTON_OBJECT]; picker.cameraOverlayView = viewOverlay; [self presentViewController:picker animated:YES completion:NULL]; } else { NSLog(@"Camera not present"); } }

因此,在从图库或相机中选择照片后,将显示这两个按钮。

代码应该是:

sourceType

如果UIImagePickerControllerSourceTypeCameraUIImagePickerControllerDelegate

,您只能添加

确保您的视图控制器中已确认{{1}}协议。

根据您的选择,点按按钮或操作表操作即可调用这些操作。

注意:UIImagePickerController的popover UI取决于iOS版设备。