0

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

Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
Ika
  • 1,271
  • 1
  • 12
  • 20
  • 1
    Back button is a navigation item of navigation bar, so how do you imaging to see part of navigation bar having hidden bar itself? Answer - you can't. If you don't want to use navigation bar, create custom button with chevron image - the look & feel would be the same. – Asperi Mar 04 '20 at 16:15
  • yes .. if you just need back button ... create custom button instead – Jawad Ali Mar 04 '20 at 17:22

1 Answers1

2

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

Jawad Ali
  • 13,556
  • 3
  • 32
  • 49