Created
April 28, 2020 14:53
-
-
Save alexnikol/05d14a9e2041ade8643b9c6366196463 to your computer and use it in GitHub Desktop.
Complex UIAlertController with field and actions
This file contains 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
//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