Skip to content

Instantly share code, notes, and snippets.

@CH3COOH
Created September 11, 2025 13:10
Show Gist options
  • Save CH3COOH/fc6e4bc0de3004855d6253da5eecb370 to your computer and use it in GitHub Desktop.
Save CH3COOH/fc6e4bc0de3004855d6253da5eecb370 to your computer and use it in GitHub Desktop.
SampleConfirmationDialog
//
// ContentView.swift
// SampleConfirmationDialog
//
// Created by KENJIWADA on 2025/09/11.
//
import SwiftUI
struct ContentView: View {
@State private var showActionSheet = false
@State private var showConfirmationDialog = false
var body: some View {
NavigationView {
VStack(spacing: 30) {
// confirmationDialogを表示するボタン
Button(action: {
showConfirmationDialog = true
}) {
Label("confirmationDialogを表示", systemImage: "text.bubble")
.frame(maxWidth: .infinity)
.padding()
.background(Color.green)
.foregroundColor(.white)
.cornerRadius(8)
}
// actionSheetを表示するボタン
Button(action: {
showActionSheet = true
}) {
Label("actionSheetを表示", systemImage: "square.stack.3d.up")
.frame(maxWidth: .infinity)
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(8)
}
Spacer()
}
.padding()
.navigationTitle("Dialog比較デモ")
.actionSheet(isPresented: $showActionSheet) {
ActionSheet(
title: Text("オプション選択"),
message: Text("以下から選択してください"),
buttons: [
.default(Text("オプション1")) {
},
.default(Text("オプション2")) {
},
.destructive(Text("削除")) {
},
.cancel(Text("キャンセル"))
]
)
}
.confirmationDialog(
"オプション選択",
isPresented: $showConfirmationDialog,
titleVisibility: .visible
) {
Button("オプション1") {
}
Button("オプション2") {
}
Button("削除", role: .destructive) {
}
// キャンセルボタンは自動的に追加される
} message: {
Text("以下から選択してください")
}
}
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment