環境
- UIAlertController
- Alert
- swift
- swift4
- swift3
- xcode
- xcode9
- iOS
実装
let alertController = UIAlertController(title: "アラート", message: "アラートのサンプルです", preferredStyle: .alert)
let action1 = UIAlertAction(title: "デフォルト", style: .default) { (action:UIAlertAction) in
print("デフォルトが押された");
}
let action2 = UIAlertAction(title: "キャンセル", style: .default) { (action:UIAlertAction) in
print("キャンセルが押された");
}
let action3 = UIAlertAction(title: "アド", style: .destructive) { (action:UIAlertAction) in
print("アドが押された");
}
alertController.addAction(action1)
alertController.addAction(action2)
alertController.addAction(action3)
self.present(alertController, animated: true, completion: nil)
参照
How to use UIAlertController in Swift.