< How to hide and show the sidebar programmatically | How to customize the display mode of NavigationSplitView > |
Updated for Xcode 14.2
SwiftUI’s NavigationSplitView
uses a system-standard width for the view it presents, but with the navigationSplitViewColumnWidth()
modifier you can attempt to customize this.
Note: The system can choose to ignore the width you specify. At the time of writing this modifier is ignored on iPhone, and on iPad only works for values lower than the default size.
In its simplest form, sending a single value to navigationSplitViewColumnWidth()
causes it to use a fixed size, no smaller or larger:
NavigationSplitView {
Text("Sidebar")
.navigationSplitViewColumnWidth(100)
} content: {
Text("Content")
.navigationSplitViewColumnWidth(200)
} detail: {
Text("Detail")
}
Download this as an Xcode project
However, if you’re happy to allow flexibility – and if you’re platform supports it, which right now might just be macOS – you an provide minimum, ideal, and maximum sizes instead, like this:
NavigationSplitView {
Text("Sidebar")
.navigationSplitViewColumnWidth(min: 100, ideal: 200, max: 300)
} content: {
Text("Content")
.navigationSplitViewColumnWidth(min: 100, ideal: 200, max: 300)
} detail: {
Text("Detail")
}
Download this as an Xcode project
SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.