Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Phenomenan/8b4df33a07fe98b94ac301575ad875bd to your computer and use it in GitHub Desktop.
Save Phenomenan/8b4df33a07fe98b94ac301575ad875bd 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