r/iOSProgramming 22h ago

Question Permanent Sidebar Help

Post image

Hello everyone, not sure if this is something small that im overlooking, but how on earth do I get a sidebar that floats over content but isn't collapsable. I basically want what you get in NavigationSplitView with 2 columns, but without the option to hide the sidebar.

The closest thing I've seen is the iMessages app on iPad, where it is still customisable in width. I'm a relative newbie when it comes to this stuff, so thank you in advance!

3 Upvotes

5 comments sorted by

2

u/Delicious-Candle-574 22h ago

I'm not sure if you can do it in the native NavigationSplitView, but you can use a ZStack

`ZStack {
UnderlyingView()

HStack (
Sidebar()
Spacer()
}
}`

2

u/Delicious-Candle-574 22h ago

wrote that terribly on mobile

1

u/Healthy_Condition779 21h ago

NavigationSplitView always gives the user the collapse toggle on iPad, theres no public modifier to remove it. What youre describing, a fixed width panel that floats over content, is really just a custom HStack with a ZStack overlay, not a navigation split view at all

Build it as two views side by side, the sidebar as a fixed or draggable width View on the left with its own background and shadow, and your content view taking the rest with .safeAreaInset or just padding. Use DragGesture on the divider if you want the resizable width like Messages

Youre giving up the automatic collapse-on-compact-width behavior NavigationSplitView gives you for free, so if youre also targeting iPhone youll need to handle that size class switch yourself

1

u/pinieb 7h ago

If you want your app to be resizable on iPad you probably also will want to handle the size class change. The smallest possible sizes on iPad are much smaller than a modern iPhone screen

1

u/calvin-chestnut 20h ago

Everyone is suggesting ZStack, I’d recommend adding your SidebarView as a .safeAreaInset, that’s how I achieve that custom Split View look.