Created
November 26, 2020 06:37
-
-
Save akio0911/a0cf433748a268c665351bcdc58572be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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