I want to hide the navigation bar and display only the back button in SwiftUI

812 Views Asked by At

navigationBarTitle is hidden. How can I display the back button in this state?

struct SampleView: View {
    var body: some View {
        ScrollView() {
            Text("text")
        }
        .navigationBarTitle("")
        .navigationBarHidden(true)
    }
}

When you do the following, a blank will appear at the top. Also, if you scroll, a bar will be displayed.

struct SampleView: View {
    var body: some View {
        ScrollView() {
            Text("text")
        }
        .navigationBarTitle("")
    }
}

enter image description here

1

There are 1 best solutions below

0
Jawad Ali On BEST ANSWER

Here is the way to add custom button instead of navigationBar

struct DestinationView: View {

    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
    var body: some View {

        VStack(alignment: .center, spacing: 0){
        Button(action: {
           self.presentationMode.wrappedValue.dismiss()
        }) {
            Image(systemName: "backward.fill").padding()
            Spacer()
        }
            Spacer()
        }
        .navigationBarTitle("")
        .navigationBarHidden(true)

    }
}

enter image description here