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)

f:id:tid-a24:20190315214748p:plain

カスタマイズできるもの

  • タイトル
  • メッセージ
  • ボタン(複数追加可)

注意

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)

f:id:tid-a24:20191218111117p:plain