Last active
December 20, 2017 09:54
-
-
Save runys/33014d31b671ffb712889c60be2cf5ac to your computer and use it in GitHub Desktop.
Simples alert for iOS 11 with Swift 4.
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
// 1. Creating the AlertController | |
let alert: UIAlertController = UIAlertController(title: "Teste", | |
message: "Aprendendo a fazer alertas", | |
preferredStyle: .alert) | |
// 1.1. Create the actions | |
let okAction = UIAlertAction(title: "OK", style: .default) { (okAction) in | |
// Insert here the code to be executed when the user select the action | |
print("O usuário escolheu: \(okAction.title!)") | |
} | |
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (cancelAction) in | |
// Insert here the code to be executed when the user select the action | |
print("O usuário escolheu: \(cancelAction.title!)") | |
} | |
// 1.2. Add the actions to the AlertController | |
alert.addAction(okAction) | |
alert.addAction(cancelAction) | |
// 2. Present the alert to the user | |
self.present(alert, animated: true, completion: { | |
// Insert here the code to be executed when the alert closes | |
print("Alerta completo!") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment