Structure¶
ToolbarItem¶
A model to represent a navigation item.¶
Declaration¶
struct ToolbarItem<ID, Content> : ToolbarContent where Content : View
Overview¶
A model that represents a toolbar or navigation item.
A ToolbarItem is essentially the following structure:
struct ToolbarItem<ID, Content: View> {
let id: ID
let placement: ToolbarItemPlacement
let content: Content
}
Adding toolbar items¶
struct ExampleView: View {
var body: some View {
NavigationView {
Text("Hello, World!")
.toolbar {
ToolbarItem(id: "bananas") {
Text("🍌🍌")
}
}
}
}
}

Placing a toolbar item on the navigation bar¶
ToolbarItem can be explicitly placed on the navigation bar using either navigationBarLeading or navigationBarTrailing. For example:
struct ExampleView: View {
var body: some View {
NavigationView {
Text("Hello, World!")
.toolbar {
ToolbarItem(id: "bananas", placement: .navigationBarLeading) {
Text("🍌🍌")
Spacer()
}
}
}
}
}

Availability¶
iOS 14.0+
macOS 11.0+
tvOS 14.0+
watchOS 7.0+
Topics¶
Instance Property¶
id The stable identity of the entity associated with this instance.
Initializer¶
init(id:placement:showsByDefault:content:) Creates a toolbar item with the specified placement and content, which allows for user customization.
init(placement:content:) Creates a toolbar item with the specified placement and content.
Type Alias¶
Body The type of content representing the body of this toolbar content.