Remove back button text from navigationbar in SwiftUI

前端 未结 3 1634
清酒与你
清酒与你 2021-01-07 02:53

I\'ve recently started working in SwiftUI, came to the conclusion that working with navigation isn\'t really great yet. What I\'m trying to achieve is the following. I final

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-07 03:32

    I have found a straightforward approach to remove the back button text using SwiftUI only, and keeping the original chevron.

    import SwiftUI
    
    struct ContentView: View {
      
      @Environment(\.presentationMode) var presentation
      
      var body: some View {
        VStack {
          // Your main view code here
        }
        .navigationBarBackButtonHidden(true)
        .navigationBarItems(leading: Button(action: { presentation.wrappedValue.dismiss() }) {
          Image(systemName: "chevron.left")
            .foregroundColor(.blue)
            .imageScale(.large)
        })
      }
    }
    

提交回复
热议问题