How do I add items to toolbar in macOS?
Generated on 8/3/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.
Squeeze the most out of Apple Pencil
New in iOS 18, iPadOS 18, and visionOS 2, the PencilKit tool picker gains the ability to have completely custom tools, with custom attributes. Learn how to express your custom drawing experience in the tool picker using the same great tool picking experience available across the system. Discover how to access the new features of the Apple Pencil Pro, including roll angle, the squeeze gesture, and haptic feedback.
Elevate your tab and sidebar experience in iPadOS
iPadOS 18 introduces a new navigation system that gives people the flexibility to choose between using a tab bar or sidebar. The newly redesigned tab bar provides more space for content and other functionality. Learn how to use SwiftUI and UIKit to enable customization features – like adding, removing and reordering tabs – to enable a more personal touch in your app.
What’s new in privacy
At Apple, we believe privacy is a fundamental human right. Learn about new and improved permission flows and other features that manage data in a privacy-preserving way, so that you can focus on creating great app experiences.