'How to change back button text in iPad in Swift UI?

Working on iPhone, iPad and Mac OS app, which has login screen. I took login View in NavigationView, when I tap on back button the login view will slide as split view. Now I want to change back button text to Login text.

Any one have any idea how&where to change for this?

backbutton text



Solution 1:[1]

You can create a custom view for the button

struct BackButton: View {
    
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
    var foregroundColor: Color
    
    var body: some View {
        Button(action: { presentationMode.wrappedValue.dismiss()}) {
            HStack {
                
                Image(systemName: Image.arrowLeft)
                    .foregroundColor(foregroundColor)
                    .aspectRatio(contentMode: .fit)
                Text("the text you need")
                    .foregroundColor(foregroundColor)
            }
        }
    }
}

after you can use it's some views:

@Environment(\.presentationMode) var presentationMode
    var body: some View {
            NavigationView {
                    ScrollView {
                     
                    }.navigationBarItems(leading: BackButton(presentationMode: _presentationMode, foregroundColor: .whiteTextColor))
                }
        }

Also before you need delete default button, you can use it inside NavigationLink()

NavigationLink(destination: SomeView()
                            .navigationBarBackButtonHidden(true)
                            .navigationBarTitle("", displayMode: .inline)
                            .navigationBarHidden(true),
                           isActive: self.$isNext,
                           label: { EmptyView() })

Result: enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sergio_veliz