Home > Back-end >  Is it possible to start the NavigationSplitView in an expanded state on macOS using SwiftUI?
Is it possible to start the NavigationSplitView in an expanded state on macOS using SwiftUI?

Time:07-14

enter image description here

I like the sidebar to be opened at launch.

However when I build and run the app, this is what I get.

enter image description here

So I need to click on the sidebar icon to show it. This is not the behavior I want. Is it possible to change this?

CodePudding user response:

Just add some component to the sidebar: part, then the left side bar will be shown(code is below the image).enter image description here

    NavigationSplitView(sidebar: {
        Text("Side bar")
    }, detail:  {
        Text("Main part")
 
    })

CodePudding user response:

@State private var columnVisibility =
    NavigationSplitViewVisibility.doubleColumn

var body: some View {
    NavigationSplitView(columnVisibility: $columnVisibility) {
        Text("Side bar")
    } detail: {
        Text("Main part")
    }
}
  • Related