It is the one that appears when you tap the logout button.
//Create alert
let alert = UIAlertController(title: "Do you want to log out?", message: "When you log out, the notification settings will be reset.", preferredStyle: .alert)
//Alert button
alert.addAction(UIAlertAction(title: "Cancel", style: .default))
alert.addAction(UIAlertAction(title: "Logout", style: .default, handler: { action in }))
//Display alerts
present(alert, animated: true, completion: nil)
First, create an instance with UIAlertController
by specifying title
, mesaage
, preferredStyle
.
Next, create a button to operate the alert.
You can create a button with alert.addAction (UIAlertAction (title:" ", style :, handler :))
. This is the default and you can omit handler
if you don't want to tap the alert button and do anything. ** (If you delete the handler, it means cancel the operation.) **
Next, if you want to do something when you tap the alert button, prepare a closure {action in}
in the handler
and describe the process in the closure, and the contents will be executed.
Finally, display an alert with present (alert, animated: true, completion: nil)
and you're done!
If you want to change the color of the cancel button to red, specify style: .destructive
of UIAlertAction
.
Recommended Posts