[TIL] iOS swiftUI 뒤로가기 버튼 구현

Captainjack·2022년 3월 28일
0

TIL

목록 보기
141/260
struct ChangeName: View {
    @Binding var defaultName: String
    @State var changeprofileName: String = ""
    
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
    
    var body: some View {
        TextField(self.defaultName, text: $changeprofileName).modifier(ClearButton(changeprofileName: $changeprofileName))
        .navigationBarTitle(LocalizedStringKey("mypage.name.title"), displayMode: .inline)
        .navigationBarBackButtonHidden(true)
        .navigationBarItems(leading:
            HStack {
            //TODO: 닉네임을 취소로 바꾸기
            Button(action: {
                self.presentationMode.wrappedValue.dismiss()
                }) {
                    Text(LocalizedStringKey("mypage.back.button"))
            }
            .foregroundColor(Color.white)
            },trailing:
                HStack {
                    Button(LocalizedStringKey("mypage.save.button"))
                    { /*code*/ }
                }
        )
    }
}

출처

https://kka7.tistory.com/276

https://stackoverflow.com/a/59822675/15746954

profile
til' CTF WIN

0개의 댓글