struct ConfirmationDialog: View {
@State private var showDialog = false
}
트리거되는 뷰에 추가하는 것이 보통이다.
title
: 다이얼로그 제목
isPresented
: 팝업 유무 관리 변수
titleVisibility
: 제목을 어떻게 처리할지 결정. 기본값은 .automatic(파라미터 자체를 사용하지 않으면 기본으로 적용)
struct ConfirmationDialog: View {
@State private var showDialog = false
var body: some View {
Button {
} label: {
Text("")
}
.confirmationDialog("컬러 선택", isPresented: $showDialog) {
Button("Red") {
}
Button("Green") {
}
Button("Blue") {
}
Button(role: .destructive) {
} label: {
Text("Reset")
}
Button(role: .cancel) {
} label: {
Text("취소")
}
} message: {
Text("다이얼로그에 표시할 메시지")
}
}
}
toggle
혹은 = true
등으로 작업
...
.confirmationDialog("컬러 선택", isPresented: $showDialog, presenting: ColorData.samples) { colors in
ForEach(colors) { item in
Button(item.title) {
color = item.color
}
}
...
} message: { _ in
...
}