Created
May 21, 2019 02:17
-
-
Save post799/4e6401ede215a4d40f1b6df58f91b90c to your computer and use it in GitHub Desktop.
imagePicker
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,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