Take picture or take from swift library 3

2

How can I put a button when I click on the option to choose a photo from the library or take one directly?

At the moment I can only use one of the two options via code.

@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*/
    }
    
asked by Miquel Coll 22.09.2016 в 12:14
source

1 answer

1

If you use UIImagePickerController how you already do. Code of this question in the Original OS:

import UIKit


class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {

@IBOutlet var imageView: UIImageView!
@IBOutlet var chooseBuuton: UIButton!
var imagePicker = UIImagePickerController()

@IBAction func btnClicked(){

        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){
            println("Button capture")


            imagePicker.delegate = self
            imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum;
            imagePicker.allowsEditing = false

            self.presentViewController(imagePicker, animated: true, completion: nil)
        }

}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){
    self.dismissViewControllerAnimated(true, completion: { () -> Void in

    })

    imageView.image = image

}
}

I think that given your concrete code is simply to modify the imagePicker that you have defined so that it is of type SavedPhotosAlbum instead of photoLibrary :

self.imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum

Also the UIButton defined is the one that allows you to choose.

    
answered by 22.09.2016 / 12:25
source