Created
May 26, 2018 17:16
-
-
Save jbarros35/8b7af5f6eb2469d41e15a57ddbb86951 to your computer and use it in GitHub Desktop.
Swift alerts standards
This file contains hidden or 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
static func showStandardMessage(reference: UIViewController, title: String, message: String) { | |
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) | |
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) | |
alert.view.setNeedsLayout() | |
reference.present(alert, animated: true, completion: nil) | |
} | |
static func showStartCancel(reference: UIViewController, title: String, message: String, callback: @escaping (UIAlertAction)->()) { | |
// create the alert | |
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) | |
// add the actions (buttons) | |
alert.addAction(UIAlertAction(title: "Start", style: UIAlertActionStyle.default, handler: callback)) | |
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil)) | |
// show the alert | |
alert.view.setNeedsLayout() | |
reference.present(alert, animated: true, completion: nil) | |
} | |
// REMARK: yes or no button alert | |
static func showYesNo(reference: UIViewController, title: String, message: String, callbackYes: @escaping (UIAlertAction)->(), callbackNo: @escaping (UIAlertAction)->(), buttonText: [String]) { | |
// create the alert | |
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) | |
// add the actions (buttons) | |
alert.addAction(UIAlertAction(title: buttonText[0], style: UIAlertActionStyle.default, handler: callbackYes)) | |
alert.addAction(UIAlertAction(title: buttonText[1], style: UIAlertActionStyle.cancel, handler: callbackNo)) | |
// show the alert | |
alert.view.setNeedsLayout() | |
reference.present(alert, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment