gist.github.com当我从图库中选择图片时,如何在UIImagePickerController
popover中添加自定义按钮?
答案 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
如果UIImagePickerControllerSourceTypeCamera
为UIImagePickerControllerDelegate
确保您的视图控制器中已确认{{1}}协议。
根据您的选择,点按按钮或操作表操作即可调用这些操作。
注意:UIImagePickerController的popover UI取决于iOS版设备。