Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created November 25, 2018 16:36
Show Gist options
  • Save vialyx/dff0768018ad600df19d79e651b265cd to your computer and use it in GitHub Desktop.
Save vialyx/dff0768018ad600df19d79e651b265cd to your computer and use it in GitHub Desktop.
import UIKit
final class ViewController: UIViewController {
@IBAction func photoLibraryDidTap(_ sender: Any) {
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
present(imagePickerController, animated: true, completion: nil)
}
}
// MARK: - UIImagePickerControllerDelegate
extension ViewController: UIImagePickerControllerDelegate {
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
print("imagePickerControllerDidCancel")
dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
print("imagePickerController didFinishPickingMediaWithInfo: \(info)")
if let image: UIImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
// Here you can manage image
print("image size: \(image.size)")
}
dismiss(animated: true, completion: nil)
}
}
// MARK: - UINavigationControllerDelegate
extension ViewController: UINavigationControllerDelegate {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment