SwiftUI Custom Back Button Text for NavigationView

爷,独闯天下 提交于 2020-05-29 06:39:38

问题


How can I change the back button text in a NavigationView when a new View is pushed?

The default shows "Back" but I want to change it so something.

Is that currently possible in SwiftUI?


回答1:


Full Code:

struct SampleDetails: View {
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>

    var btnBack: some View {
        Button(action: {self.presentationMode.wrappedValue.dismiss()}) {
            HStack {
                Image("ic_back") // set image here
                .aspectRatio(contentMode: .fit)
                .foregroundColor(.white)
                Text("Go back")
            }
        }
    }

    var body: some View {
        List {
            Text("sample code")
        }
        .navigationBarBackButtonHidden(true)
        .navigationBarItems(leading: btnBack)
    }
}

For more clarification click here.



来源:https://stackoverflow.com/questions/58906365/swiftui-custom-back-button-text-for-navigationview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!