How do I add items to toolbar in macOS?
Asked on 08/03/2024
1 search
To add items to a toolbar in macOS, you can use the NSToolbar
class, which has been enhanced in macOS Sequoia to give you more control over display mode, displayed items, and item visibility. Here are some key points to consider:
-
Display Mode Customization: You can offer a choice of style (icon only or with text labels) using the
allowsDisplayModeCustomization
property. This is enabled by default. Ensure your toolbar has an identifier so that AppKit can save the style preference, and make sure all your toolbar items have good labels. -
Item Identifiers: Use the new
itemIdentifiers
property to set a toolbar's item identifiers. This automatically handles minimal additions and removals for you. Note that ifallowsUserCustomization
is enabled, changing values here will override any customizations, so use this for dynamic, non-customizable toolbars. -
Item Visibility: You can conditionally hide and show toolbar items using the new
isHidden
property. Hidden items still appear in customization, allowing users to choose where they want them to appear when made visible.
For more detailed information, you can refer to the session What’s new in AppKit (15:21).
Relevant Sessions

Get started with Writing Tools
Learn how Writing Tools help users proofread, rewrite, and transform text in your app. Get the details on how Writing Tools interact with your app so users can refine what they have written in any text view. Understand how text is retrieved and processed, and how to support Writing Tools in custom text views.

Dive deep into volumes and immersive spaces
Discover powerful new ways to customize volumes and immersive spaces in visionOS. Learn to fine-tune how volumes resize and respond to people moving around them. Make volumes and immersive spaces interact through the power of coordinate conversions. Find out how to make your app react when people adjust immersion with the Digital Crown, and use a surrounding effect to dynamically customize the passthrough tint in your immersive space experience.

What’s new in AppKit
Discover the latest advances in Mac app development. Get an overview of the new features in macOS Sequoia, and how to adopt them in your app. Explore new ways to integrate your existing code with SwiftUI. Learn about the improvements made to numerous AppKit controls, like toolbars, menus, text input, and more.