Reputation: 3035
E.g. if you navigate from View A to View B, View B will typically display a back button on the left side of the navigation bar that says "< View A" (assuming that View A's title is "View A"
).
When I don't have a title in View A, the back button in view B is simply "<"
which is as expected, because view A has no title.
Now is there a way to make it so that if there is no title in the previous view, it should always say "< Back"
?
Upvotes: 1
Views: 791
Reputation: 3426
You can make your own back button which can be individualized:
Put this at the top of your view:
@Environment(\.presentationMode) var presentationMode
var btnBack : some View { Button(action: {
self.presentationMode.wrappedValue.dismiss()
}) {
Text("< Back")
}
}
And at at the end of your Stack in that View:
.navigationBarBackButtonHidden(true)
.navigationBarItems(leading: btnBack)
Upvotes: 1