SwiftUI macOS Xcode Style Toolbar
Okay, I found a trick that works:
- Set the scene's
windowStyle
toHiddenTitleBarWindowStyle
, which both hides the title and removes the white background:
WindowGroup {
ContentView()
}
.windowToolbarStyle(UnifiedCompactWindowToolbarStyle())
.windowStyle(HiddenTitleBarWindowStyle())
(Note that I don't set the scene name to an empty string, as that's no longer needed and it messed up the window name in the "Window" menu too)
- To force a divider between the toolbar and the detail view content, stretch the detail content to fill the whole space and put a
Divider
behind it:
Text("Detail")
.frame(minWidth: 200, maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
.background(VStack {
Divider()
Spacer()
})
.toolbar { ...
That seems to do it!
How do you create a Preferences Style toolbar in SwiftUI for macOS?
Are you using the SwiftUI App Lifecycle? If so, add a TabView
to your Settings
view and the tabs will appear in the toolbar automatically:
Settings {
TabView {
PreferencesView()
.tabItem {
Label("General", systemImage: "gearshape")
}
}
}
If you’re not using the SwiftUI app lifecycle, then I think you’ll need to build this style of toolbar manually using NSToolbar
.
Related Topics
Why Does a Public Class/Struct in Swift Require an Explicit Public Initializer
Reducing the Number of Brackets in Swift
Swift Error When Trying to Access Dictionary: 'Could Not Find Member 'Subscript''
Why Is There a Memory Leak at String Creation in Swift
How to Add Initializers in Extensions to Existing Uikit Classes Such as Uicolor
Cannot Assign to Property: 'Xxxx' Is a Get-Only Property
How to Get Motion Events with the Apple Tv Remote
What Is a Good Alternative for Static Stored Properties of Generic Types in Swift
Swiftui: How Do Style Text View with Different Font and Colour on String Subranges
Storyboard Entry Point Missing
Nspredicate with Swift and Core Data
How to Check If a String Contains Chinese in Swift
Converting String to Data in Swift 3.0
How to Pass Protocol with Associated Type (Generic Protocol) as Parameter in Swift
Mkmapview Not Clustering Annotation on Zooming Out Map in Swift