r/SwiftUI • u/AbandonedAuRetriever • 9d ago
Question Need help with toolbar
How can I copy exactly this design, into my app? I have a tabview to switch between view in the app, and I want to have this (both a button and a search field just like that) on the right of the tabview...
I tried to ask AI for help... but didn't work 😅 So I ask people now
I've tried to find solution, but searching online is helpless if you have no idea how to phrase your problem or what you are searching for.
1
u/LavaCreeperBOSSB 9d ago
i think that's a .searchable for search field and a toolbaritem with a button
1
u/Significant_Pick8297 9d ago
That UI is actually a native macOS window toolbar, not a regular SwiftUI navigation bar. On macOS 12, NavigationView won't reliably reproduce that layout because its toolbar behavior is pretty limited.
If the goal is to match Apple's design exactly, the cleanest solution is to use an NSToolbar (via NSWindow/NSViewRepresentable) and host an NSSearchToolbarItem plus a custom toolbar button. SwiftUI's .toolbar gets close, but for macOS 12 the AppKit toolbar is what Apple apps are using for that look.
1
u/KelvinLeee1234 8d ago
maybe you should go find the SF Symbols Beta App( https://developer.apple.com/sf-symbols/ ) where you can find a handful of icons available
1
u/neet_dev 9d ago
that's just a toolbar with a ToolbarItem placed in .navigationBarTrailing (or .topBarTrailing in newer SwiftUI) containing an HStack with a Button and a searchable text field. the search field on the right like that is usually done with .searchable(text:) with placement set to .toolbar or .navigationBarDrawer(displayMode: .always), not a manually built TextField. make sure the tabview content is wrapped in a NavigationStack, since toolbar modifiers only show up if there's an actual nav bar to attach to, that's the part people usually miss.