SwiftUI Toolbar Features
Quick Reference
Feature | Modifier/Type | Purpose |
---|---|---|
.toolbar(id:) | Customizable toolbar | User can add/remove/reorder |
ToolbarSpacer | Spacing control | Fixed or flexible spacing |
.searchToolbarBehavior() | Search field display | Minimize/expand behavior |
DefaultToolbarItem | System items | Reposition system controls |
.matchedTransitionSource() | Transitions | Zoom from toolbar items |
Customizable Toolbars
Basic Setup
Spacer Types
Search Integration
Minimize Behavior
Repositioning Search
Placement Options
Common Placements
Large Subtitle
Visual Effects
Matched Transitions
Background Visibility
System Items
Default Items
Platform Considerations
iOS/iPadOS
macOS
Common Patterns
Dynamic Toolbar
Grouped Actions
Contextual Items
Best Practices
- Unique IDs: Use meaningful identifiers for customizable items
- Logical Groups: Use spacers to group related actions
- Platform Awareness: Test on all target platforms
- Consistent Placement: Follow platform conventions
- Minimal Items: Avoid overcrowding toolbars
Troubleshooting
Issue | Solution |
---|---|
Items not customizable | Add id to toolbar and items |
Search not minimizing | Apply .searchToolbarBehavior(.minimize) |
Transition not working | Check namespace and ID match |
Items hidden | Check placement compatibility |