Skip to content

Instantly share code, notes, and snippets.

@akio0911
Created November 26, 2020 06:37
Show Gist options
  • Save akio0911/a0cf433748a268c665351bcdc58572be to your computer and use it in GitHub Desktop.
Save akio0911/a0cf433748a268c665351bcdc58572be to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func didTapButton(_ sender: Any) {
let picker = UIImagePickerController()
// picker.sourceType = .camera
picker.sourceType = .photoLibrary
picker.delegate = self
present(picker, animated: true)
}
}
extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
imageView.image = info[.originalImage] as? UIImage
dismiss(animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment