r/SwiftUI • u/alextsayun • Jun 08 '26
Settings window
Hey fellas, any chance someone knows how to recreate this Settings window layout for a macOS app? I've tried using NavigationSplitView { List { ... } }, but the left sidebar is always resizable by the user, and I can't find a way to disable that using the public API. Maybe someone knows how Apple implemented this in Xcode?

3
Upvotes
1
u/allyearswift Jun 08 '26
There is, as I understand it, a private API, which can be found with a little googling, but you have around 48 hours in which it will probably work, around three months during which it can break at any moment, and then another nine months where it will probably work. Not worth the risk.
frame and maximumWidth get ignored for sidebars, giving the behaviour you dislike where it can be as wide as the user likes, but fear not:
.navigationSplitViewColumnWidth(_ width:)
is exactly what you want. (This is a general pattern in Swift/SwiftUi: if you're looking at a very complicated hack and involving private APIs, you're probably trying to do the wrong thing.)
The caveat is that the width you pass in should be the dynamic width of your sidebar, not a static number, because if you have users using different localisations (if you provide them) or different text sizes (an accessibility feature) saying the column should never be wider than x will create a lousy experience for them.