Created using Ventura and Xcode 15.2. Published: April 28th 2025
The simplest Toolbar of all is just to use Buttons.
This is a style I like because it includes labels with the icons, but for a lot of items clipping can occur which then looks wrong. There is another style that includes labels as we'll see later on.
This is the most correct way to code a toolbar as it allows for user customization, which includes showing labels and rearranging the items. The image above is after "Icon and Text" has been selected from the contextual menu for the toolbar. Customization requires an id be supplied to the toolbar and each item should have a unique id. Any user customization is automatically saved and restored.
The optional modifier .
hides the toolbar item by default, this is useful for scenarios where the average customer might not need such a button.
If your Toolbar has lots of default items, the expanded option is available. Simply specify .
on the window scene.
In the opposite direction, a unified compact toolbar is smaller than the other options. Use .
on the window scene.
Adding a search field to the toolbar is easier than you think, simply add the .
modifier to a view within your content view.
You can give toolbar items a keyboard shortcut so the customer doesn't even have to move the mouse to activate an item.
With the unified or automatic toolbar placement, toolbar items start on the far right and fill in towards the left. You can make a Toolbar item fill in from the left, Apple calls this "Navigation" placement and to be consistent with other applications, it's probably best NOT to put any other buttons than nav buttons there.
For better accessibility, you can provide a more detailed description of what a button does, so when the customer mouses over the button they get a clearer idea of what the button is going to do.
I wouldn't recommend this option, but I've included it incase it's a style that is needed for a particular application. Simply include the .
modifier on the window scene (like the
).
The toolbar can use other controls than just
, in this example I've added a
and a
.
Putting a segmented picker too close to the search field can result in it becoming trapped and unaccessible from the chevron menu when the search field is highlighted and then loses focus. I have filed this as a bug with Apple FB17392294. It is worth noting that the Finder does not have this problem.
A workaround is to place the segmented picker as the first item in the toolbar, so that it never enters the chevron menu in the first place.
Believe it or not, but there's built-in functionality for adjusting the color of the toolbar. Simply add the following modifier to the root view.
Site managed by Strawberry Software's Lifeboat - running on DigitalOcean's platform.
Pages
Products Contact Us Weblog SwiftUI Dev PromotionsCompany
About Us Environment Privacy Terms Update PlansConnect
Bluesky Facebook Threads X / Twitter Mailing List