Discussion
議論
Use navigationBarItems(leading:trailing:)
to add navigation bar items to the leading and trailing edges of the navigation bar for this view.
This modifier only takes effect when this view is inside of and visible within a NavigationView
.
この修飾子は、このビューが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 and trailing edges 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!")
}
}, trailing:
HStack {
Button("Favorites") {
print("Favorites tapped!")
}
Button("Specials") {
print("Specials tapped!")
}
}
)
}
}
}