Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. @IBAction func LoadImage(_ sender: UIButton) {
  2. let imageActionSheet = UIAlertController(title: "Add Picture", message: "how would you like to add your recipt", preferredStyle: UIAlertControllerStyle.actionSheet)
  3.  
  4. let newPhotoAction = UIAlertAction(title: "Take Photo", style: .default ){ action in
  5.  
  6. if UIImagePickerController.isSourceTypeAvailable(.camera) {
  7. imagePicker.sourceType = UIImagePickerControllerSourceType.camera
  8. imagePicker.cameraCaptureMode = .photo
  9. imagePicker.modalPresentationStyle = .fullScreen
  10. self.present(imagePicker,animated: true,completion: nil)
  11.  
  12. }
  13. }
  14.  
  15. let existingPhotoAction = UIAlertAction(title: "Existing Photo", style: .default ){ action in
  16. if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
  17. imagePicker.sourceType = .photoLibrary
  18. imagePicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
  19. imagePicker.modalPresentationStyle = .popover
  20. self.present(imagePicker, animated: true, completion: nil)
  21. }
  22. }
  23.  
  24. let cancelAction = UIAlertAction(title: "Cancel", style: .cancel ){ action in
  25. self.dismiss(animated: true, completion: nil)
  26. }
  27.  
  28.  
  29. imageActionSheet.addAction(newPhotoAction)
  30. imageActionSheet.addAction(existingPhotoAction)
  31. imageActionSheet.addAction(cancelAction)
  32.  
  33.  
  34. // We need to provide a popover sourceView when using it on iPad
  35. imageActionSheet.popoverPresentationController?.sourceView = sender as UIView
  36.  
  37. // Present the AlertController
  38. self.present(imageActionSheet, animated: true, completion: nil)
  39.  
  40.  
  41.  
  42.  
  43. func imagePickerController(_ picker: UIImagePickerController,
  44. didFinishPickingMediaWithInfo info: [String : Any]){
  45. ImageWork.image = info[UIImagePickerControllerOriginalImage] as? UIImage
  46. dismiss(animated:true, completion: nil)
  47. }
  48.  
  49. func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
  50. dismiss(animated: true, completion: nil)
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement