Search
Duplicate

액션 시트

태그

액션 시트란?

사용 예제

1.
버튼 생성
GradientButton(text: "Change yout profile picture")
Swift
복사
2.
상태 변수 생성
@State private var showActionSheet = false
Swift
복사
액션 시트를 보여줄지를 상태변수로 지정
3.
버튼에 온탭 제스쳐 추가 및 상태변수 업데이트
onTapGesture { showActionSheet = true }
Swift
복사
4.
액션 시트 구현
GradientButton(text: "Change yout profile picture") .onTapGesture { showActionSheet = true } .actionSheet(isPresented: $showActionSheet, content: { ActionSheet(title: Text("Change yout profile picture"), message: Text("Pick a photo that you like"), buttons: [ .default(Text("From Library"), action: { print("picked from library") }), .default(Text("From camera"), action: { print("picked from camera") }), .cancel() ]) })
Swift
복사

설명

func actionSheet(isPresented: Binding<Bool>, content: () -> ActionSheet) -> some View
Swift
복사
액션 시트를 present 하는 메서드 이다.

Parameters

isPresented
바인딩 된 불리언 값을 전달해야한다. 이 불리언 값이 true 이면 content 클로져 안에 있는 액션시트가 present 된다.
시트의 default action button 을 누르게 되면 시스템은 isPresented 값을 false 로 설정한다.
content
present 할 액션시트를 리턴한다.