Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Custom Back Button Text for NavigationView

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?

like image 538
SwiftiSwift Avatar asked Nov 17 '19 23:11

SwiftiSwift


Video Answer


1 Answers

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.

like image 152
Md. Ashikur Rahman Avatar answered Oct 22 '22 20:10

Md. Ashikur Rahman