swiftUI 코드 정리

구구·2023년 4월 5일
0
post-thumbnail

🌿 Alert

struct ContentView: View {
    @State private var showing = false
    
    var body: some View {
        Button("Alert 띄우기") {
            showing = true
        }
        .alert("메시지", isPresented: $showing) {
            Button("OK", role: .cancel) {}
        }
    }
}

🌿 Action Sheet

struct ContentView: View {
    @State var showingSheet = false
    
    var body: some View {
        Button(action: {
            self.showingSheet = true
        }) {
            Text("Action Sheet 띄우기")
        }
        .confirmationDialog("타이틀", isPresented: $showingSheet) {
            Button("제거", role: .destructive){}
            Button("취소", role: .cancel) {}
        }
    }
}

0개의 댓글