Skip to content

Instantly share code, notes, and snippets.

@alexnikol
Created April 28, 2020 14:53
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 alexnikol/05d14a9e2041ade8643b9c6366196463 to your computer and use it in GitHub Desktop.
Save alexnikol/05d14a9e2041ade8643b9c6366196463 to your computer and use it in GitHub Desktop.
Complex UIAlertController with field and actions
//We can change preferredStyle: .actionSheet
let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
//Add Cancel Action
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
//Add Default Action
alert.addAction(UIAlertAction(title: "Default", style: .default, handler: { action in
print("Default button did tap")
}))
//Add Default2 Action
let default2Action = UIAlertAction(title: "Default 2", style: .default, handler: { action in
print("Default2 button did tap")
})
alert.addAction(default2Action)
alert.preferredAction = default2Action
//Add Default Action
alert.addAction(UIAlertAction(title: "Destructive", style: .destructive, handler: { action in
print("Destructive button did tap")
}))
//Add Default Action
alert.addTextField { (field) in
field.placeholder = "Pet Name"
field.addTarget(self, action: #selector(self.editingChanged), for: .editingChanged)
}
self.present(alert, animated: true, completion: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment