Skip to content

Instantly share code, notes, and snippets.

@cafielo
Created January 31, 2021 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cafielo/2d5989144f92274e01aca4c92becc2ed to your computer and use it in GitHub Desktop.
Save cafielo/2d5989144f92274e01aca4c92becc2ed to your computer and use it in GitHub Desktop.
let alertController = UIAlertController(title: nil, message: "Alert message.", preferredStyle: .actionSheet)
let defaultAction = UIAlertAction(title: "Default", style: .default, handler: { (alert: UIAlertAction!) -> Void in
// Do some action here.
})
let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (alert: UIAlertAction!) -> Void in
// Do some destructive action here.
})
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: { (alert: UIAlertAction!) -> Void in
// Do something here upon cancellation.
})
alertController.addAction(defaultAction)
alertController.addAction(deleteAction)
alertController.addAction(cancelAction)
//
if let popoverController = alertController.popoverPresentationController {
popoverController.sourceView = self.view
popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
}
self.present(alertController, animated: true, completion: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment