How to Use the toolbar() Modifier in SwiftUI

Learn how to use the toolbar() modifier in SwiftUI. The toolbar() modifier allows you to add views to the toolbar or to the navigation bar, it would soon replace the deprecated navigationBarItems() modifier.

Just add the modifier to any view inside the NavigationView such as the example below, then add ToolbarItem or ToolbarItemGroup to build the view.

ToolbarItem creates a toolbar item with the specified placement and content, which allows for user customization.

There are two types of placements.

  • Semantic placements such as the principal and navigation. SwiftUI is smart enought to determine the where they should appear.
  • Positional placements allows you put precisely where you want the item to appear eg. navigationBarLeading

Leave a Reply

Your email address will not be published. Required fields are marked *