アラートを使ってダイアログ表示させます。
最も汎用的に使えるソースコードを記載しています。
プレビュー
ソースコード
@State private var showAlert = false
var body: some View {
Button("ダイアログを表示します") {
showAlert = true
}
.alert(isPresented: $showAlert) {
Alert(
title: Text("タイトル"),
message: Text("サブタイトル"),
primaryButton: .default(
Text("OK"),
action: {} //OKボタンの処理
),
secondaryButton: .destructive(
Text("キャンセル"),
action: {} //キャンセルボタンの処理
)
)
}
}