Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBAction func LoadImage(_ sender: UIButton) {
- let imageActionSheet = UIAlertController(title: "Add Picture", message: "how would you like to add your recipt", preferredStyle: UIAlertControllerStyle.actionSheet)
- let newPhotoAction = UIAlertAction(title: "Take Photo", style: .default ){ action in
- if UIImagePickerController.isSourceTypeAvailable(.camera) {
- imagePicker.sourceType = UIImagePickerControllerSourceType.camera
- imagePicker.cameraCaptureMode = .photo
- imagePicker.modalPresentationStyle = .fullScreen
- self.present(imagePicker,animated: true,completion: nil)
- }
- }
- let existingPhotoAction = UIAlertAction(title: "Existing Photo", style: .default ){ action in
- if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
- imagePicker.sourceType = .photoLibrary
- imagePicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
- imagePicker.modalPresentationStyle = .popover
- self.present(imagePicker, animated: true, completion: nil)
- }
- }
- let cancelAction = UIAlertAction(title: "Cancel", style: .cancel ){ action in
- self.dismiss(animated: true, completion: nil)
- }
- imageActionSheet.addAction(newPhotoAction)
- imageActionSheet.addAction(existingPhotoAction)
- imageActionSheet.addAction(cancelAction)
- // We need to provide a popover sourceView when using it on iPad
- imageActionSheet.popoverPresentationController?.sourceView = sender as UIView
- // Present the AlertController
- self.present(imageActionSheet, animated: true, completion: nil)
- func imagePickerController(_ picker: UIImagePickerController,
- didFinishPickingMediaWithInfo info: [String : Any]){
- ImageWork.image = info[UIImagePickerControllerOriginalImage] as? UIImage
- dismiss(animated:true, completion: nil)
- }
- func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
- dismiss(animated: true, completion: nil)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement