我有图像选择器(下面的源代码)。我想做的是...从图库中选择图像,并通过取消和接受按钮将其显示为预览。.我该怎么做?
func showPhotoSourceSelection() {
let alertController = UIAlertController.init(title: nil,
message: "You can pick image from camera or gallery",
preferredStyle: .actionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let photoLibraryAction = UIAlertAction(title: "Photo from gallery", style: .default) { (action) in
self.showImagePickerController(sourceType: .photoLibrary)
}
alertController.addAction(cancelAction)
alertController.addAction(photoLibraryAction)
if UIImagePickerController.isFlashAvailable(for: .rear) {
let cameraAction = UIAlertAction.init(title: "Photo from Camera", style: .default, handler: { (action) in
self.showImagePickerController(sourceType: .camera)
})
alertController.addAction(cameraAction)
}
viewController.present(alertController, animated: true, completion: nil)
}