1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| // 通过懒加载创建图片 - (UIAlertController *)imgSheetVC { if (_imgSheetVC == nil) { // 这里可以添加标题或者提示信息 _imgSheetVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *cameraAC = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:self.imagePicker animated:YES completion:nil]; }]; UIAlertAction *photoLibraryAC = [UIAlertAction actionWithTitle:@"图库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { self.imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; [self presentViewController:self.imagePicker animated:YES completion:nil]; }]; UIAlertAction *cancelAC = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [_imgSheetVC addAction:cameraAC]; [_imgSheetVC addAction:photoLibraryAC]; [_imgSheetVC addAction:cancelAC]; } return _imgSheetVC; }
|