navigationBarItems(leading:)
Sets the navigation bar items for this view.
Declaration
nonisolated func navigationBarItems<L>(leading: L) -> some View where L : View
Parameters
- leading:
A view that appears on the leading edge of the title.
Discussion
Use navigationBarItems(leading:) to add navigation bar items to the leading edge of the navigation bar for this view.
This modifier only takes effect when this view is inside of and visible within a NavigationView.
On iOS 14 and later, the leading item supplements a visible back button, instead of replacing it, by default. To hide the back button, use navigationBarBackButtonHidden(_:).
The example below adds buttons to the leading edge of the button area of the navigation view:
struct FlavorView: View {
var body: some View {
NavigationView {
List {
Text("Chocolate")
Text("Vanilla")
Text("Strawberry")
}
.navigationBarTitle(Text("Today's Flavors"))
.navigationBarItems(leading:
HStack {
Button("Hours") {
print("Hours tapped!")
}
Button("Help") {
print("Help tapped!")
}
}
)
}
}
}