Skip to content

Instantly share code, notes, and snippets.

@post799
Created May 21, 2019 02:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save post799/4e6401ede215a4d40f1b6df58f91b90c to your computer and use it in GitHub Desktop.
Save post799/4e6401ede215a4d40f1b6df58f91b90c to your computer and use it in GitHub Desktop.
imagePicker
import UIKit
class ViewController: UIViewController,UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var imagePicker = UIImagePickerController()
@IBOutlet weak var img: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func onClickPickImage(_ sender: UIButton) {
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
present(imagePicker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {
img.image = image
}
dismiss(animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment