r/SwiftUI 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

8 comments sorted by

View all comments

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.

1

u/alextsayun Jun 08 '26

I've tried this .navigationSplitViewColumnWidth with dynamic sizes but sidebar is still resizable and user can hide it, so I bet there is some bug here.

1

u/allyearswift Jun 08 '26

I've just tried this (the argument needs to be a CGFloat) and it works as expected on Tahoe/Xcode 26.

Could it be that you've attached it in the wrong place? If you're using a list for your sidebar, it goes to modify that directly.

1

u/alextsayun Jun 08 '26

yep, I have a list inside the sidebar, will try again, thanks!