Skip to content

Instantly share code, notes, and snippets.

@NikhilManapure
Created August 4, 2017 06:27
Show Gist options
  • Select an option

  • Save NikhilManapure/ce2aecb9a53ea871043f9df76cfa7169 to your computer and use it in GitHub Desktop.

Select an option

Save NikhilManapure/ce2aecb9a53ea871043f9df76cfa7169 to your computer and use it in GitHub Desktop.
extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func presentImagePicker(allowingEditing: Bool) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary){
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary;
imagePickerController.allowsEditing = allowingEditing
self.present(imagePickerController, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info:[String : Any]) {
if info.keys.contains(UIImagePickerControllerEditedImage) {
var image = info[UIImagePickerControllerEditedImage] as? UIImage
} else {
var image = info[UIImagePickerControllerOriginalImage] as? UIImage
}
update(with: image)
self.dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
self.dismiss(animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment