How to add a "Space" item at the toolbar with SwiftUI for macOS?
struct EditorView: View {
@ToolbarContentBuilder
func toolBarContent() -> some CustomizableToolbarContent {
ToolbarItem(id: "toggle", placement: .navigation) {
Button {
NSApp.keyWindow?
.contentViewController?
.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)),
with: nil)
} label: {
Label("Toggle Libary", systemImage: "sidebar.left")
.accessibilityLabel("Toggle Libary")
.help("Toggle Libary")
}
}
ToolbarItem(id: "sfsymbols", placement: .automatic) {
Button {
print("")
} label: {
Label("SF Symbols", systemImage: "star.square.on.square.fill")
.accessibilityLabel("SF Symbols")
.help("SF Symbols")
}
}
.defaultCustomization(.hidden)
ToolbarItem(id: "flexibleSpace", placement: .automatic) {
Spacer()
}
.defaultCustomization(.hidden)
ToolbarItem(id: "save", placement: .automatic) {
Button {
print("")
} label: {
Label("Save", systemImage: "square.and.arrow.down")
.accessibilityLabel("Save")
.help("Save")
}
}
}
var body: some View {
ZStack {
CanvasView()
}
.toolbar(id: "main") {
toolBarContent()
}
}
}
I use CustomizableToolbarContent like above code.
Spacer() will get a "FlexibleSpace" item of the toolbar.
ToolbarItem(id: "flexibleSpace", placement: .automatic) {
Spacer()
}
How can I get a "Space" item?
Thanks!