Mac CatalystでUIAlertControllerをシートとして表示する
確認バージョン:Xcode 11.3
let alertController = UIAlertController(title: "Alert", message: "", preferredStyle: .alert) alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in // handle })) present(alertController, animated: true, completion: nil)
カスタマイズできるもの
- タイトル
- メッセージ
- ボタン(複数追加可)
注意
textFieldを追加するとシートとして表示されなくなります。
let alertController = UIAlertController(title: "Alert", message: "", preferredStyle: .alert) alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in // handle })) alertController.addTextField(configurationHandler: { _ in }) present(alertController, animated: true, completion: nil)