In WWDC 2022, Apple introduced NavigationSplitView, an alternative to NavigationView. All are good before I get a problem: I don't know how to hide the toggle sidebar button.
What I want (like the Mail app, no sidebar button):

My code & result (I didn't add any code about the sidebar button in my project):
struct ContentView: View {
@State private var selection: Int = 1
@State private var search: String = ""
@State private var columnVisibility = NavigationSplitViewVisibility.all
var body: some View {
NavigationSplitView(columnVisibility: $columnVisibility) {
Sidebar(selection: $selection)
} content: {
Content(selection: $selection)
} detail: {
DetailView(selection: $selection)
}
.searchable(text: $search) {
}
}
}

Is there a way to hide it? I appreciate any help you can provide.
This is now possible as of XCode Version 15.0 beta 6 (15A5219j).
To hide the 'Hide / Show Sidebar' button add .toolbar(removing:) with a ToolbarDefaultItemKind value of .sidebarToggle to your sidebar View:
NavigationSplitView(
sidebar: {
<#T##SomeSidebarView#>
.toolbar(removing: .sidebarToggle)
},
detail: {
<#T##SomeDetailView#>
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With