Created
June 15, 2018 00:05
-
-
Save SashaTsebrii/f5a3b0a9f360befacf4a6c617e5569fc to your computer and use it in GitHub Desktop.
Alert
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
// Default alert | |
let alert = UIAlertController(title: "Did you bring your towel?", message: "It's recommended you bring your towel before continuing.", preferredStyle: .alert) | |
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { action in | |
print("Yay! You brought your towel!") | |
})) | |
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil)) | |
self.present(alert, animated: true) | |
// Alert with text fields | |
let alert = UIAlertController(title: "What's your name?", message: nil, preferredStyle: .alert) | |
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) | |
alert.addTextField(configurationHandler: { textField in | |
textField.placeholder = "Input your name here..." | |
}) | |
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in | |
if let name = alert.textFields?.first?.text { | |
print("Your name: \(name)") | |
} | |
})) | |
self.present(alert, animated: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment