简体   繁体   中英

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("")
    }
}

在此处输入图片说明

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)

    }
}

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM