How can I put a button that when clicked gives the option to choose a photo from the library or to take one directly?
At the moment I can only code one of the two options.
@IBAction func cogerImagen(_ sender: UIButton) {
self.imagePicker = UIImagePickerController()
self.imagePicker.delegate = self
self.imagePicker.sourceType = .photoLibrary
self.imagePicker.isEditing = true
present(self.imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
self.imagePicker.dismiss(animated: true, completion: nil)
/*let imageView: UIImageView = UIImageView()
imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage*/
}
If you use
UIImagePickerController
how you already do. Code for this question in the Original OS:I think given your concrete code it is simply modifying the
imagePicker
one you have defined to be of typeSavedPhotosAlbum
instead ofphotoLibrary
:Likewise, the
UIButton
defined one is the one that allows you to choose.