Skip to content

Instantly share code, notes, and snippets.

@JayachandraA
Created May 4, 2017 12:22
Show Gist options
  • Save JayachandraA/f7e6bbeb7b818f2109a4fb5f20a01cf5 to your computer and use it in GitHub Desktop.
Save JayachandraA/f7e6bbeb7b818f2109a4fb5f20a01cf5 to your computer and use it in GitHub Desktop.
//create object
let alertController = UIAlertController(title: "Login ✉︎", message: "Please enter your username/email and password.", preferredStyle: .alert)
// create action object
// which can be used to handle the different action when user tapped on any one of them
let okAction = UIAlertAction(title: "Ok", style: .default) { (action) in
//handle ok button action
print("ok button tapped")
}
let cancelAction = UIAlertAction(title: "Cancel", style: .destructive) { (action) in
//handle cancel button
print("cancel button tapped")
}
//add two button action to the alert controller
alertController.addAction(okAction)
alertController.addAction(cancelAction)
//adding user input to the alertcontroller
alertController.addTextField { (textField) in
textField.placeholder = "Enter username"
textField.keyboardAppearance = .dark
textField.keyboardType = .emailAddress
}
alertController.addTextField { (textField) in
textField.placeholder = "Enter password"
textField.keyboardAppearance = .dark
textField.isSecureTextEntry = true
}
//display
present(alertController, animated: true, completion: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment