iosswiftswiftuinavigationitem

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


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


Solution

  • 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