Created
July 4, 2016 11:15
-
-
Save stansidel/beb82fe916b3a6d64e474079d4d8e43b to your computer and use it in GitHub Desktop.
Presenting UIAlertController for uploading a photo
This file contains hidden or 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
@IBAction func loadImage(sender: AnyObject) { | |
let imagePickerActionSheet = UIAlertController(title: "Take/Upload Photo", | |
message: nil, preferredStyle: .ActionSheet) | |
if UIImagePickerController.isSourceTypeAvailable(.Camera) { | |
let cameraButton = UIAlertAction(title: "Take Photo", style: .Default, handler: { (alert) in | |
let imagePicker = UIImagePickerController() | |
imagePicker.delegate = self | |
imagePicker.sourceType = .Camera | |
self.presentViewController(imagePicker, animated: true, completion: nil) | |
}) | |
imagePickerActionSheet.addAction(cameraButton) | |
} | |
let libraryButton = UIAlertAction(title: "Choose Existing", style: .Default) { (alert) in | |
let imagePicker = UIImagePickerController() | |
imagePicker.delegate = self | |
imagePicker.sourceType = .PhotoLibrary | |
self.presentViewController(imagePicker, animated: true, completion: nil) | |
} | |
imagePickerActionSheet.addAction(libraryButton) | |
let cancelButton = UIAlertAction(title: "Cancel", style: .Cancel) { (alert) in } | |
imagePickerActionSheet.addAction(cancelButton) | |
presentViewController(imagePickerActionSheet, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment