跳转至
Structure

ToolbarItemPlacement

A structure which defines the placement of a toolbar item.

Declaration


Overview

There are two types of placements:

  • Semantic placements, such as .principal and .navigation, which denote the intent of the item being added. SwiftUI will determine the appropriate placement for the item based on this intent, as well as the current platform.
  • Positional placements, such as .navigationBarLeading, which denote a precise placement for the item, usually for a particular platform.

Toolbar placements are used with the ToolbarItem when defining a toolbar. For example:

A screenshot displaying a text view with two banana emojis in the center of the screen and a button on the bottom that reads "Bottom bar button." The button is placed at the bottom using the toolbar modifier with bottomBar placement.

Availability

iOS 14.0+

macOS 11.0+

tvOS 14.0+

watchOS 7.0+

Topics


Type Property

automatic The item is placed automatically, depending on many factors including the platform, size class, or presence of other items.

bottomBar The item is placed in the bottom toolbar. Applies to iOS, iPadOS, and Mac Catalyst.

cancellationAction The item represents a cancellation action for a modal interface.

confirmationAction The item represents a confirmation action for a modal interface.

destructiveAction The item represents a destructive action for a modal interface.

navigation The item represents a navigation action.

navigationBarLeading The item is placed in the leading edge of the navigation bar. Applies to iOS, iPadOS, tvOS, and Mac Catalyst.

navigationBarTrailing The item is placed in the trailing edge of the navigation bar. Applies to iOS, iPadOS, tvOS, and Mac Catalyst.

primaryAction The item represents a primary action.

principal The item is placed in the principal item section.

status The item represents a change in status for the current context.