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

5576 단어 iOSTILTIL
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

좋은 웹페이지 즐겨찾기