NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

MacOS SwifUI - View/Window size control with 2 sidebars (Left and right sides)

Forums > macOS

I want to layout a window that works in the same way Xcode works. By this I mean it has a sidebar on both sides and a document view in the middle.

The left sidebar is the "master" and the document and right sidebar will display data based on the master item selected.

That all works, and the user can adjust the size of the two side bars.

The problem is the size of the side bars as set by the user dragging is overridden when a new master item is selected or when the window is resized by the user.

The left side bar is working as expected, the right side bar is self adjusting when the window size is changed by the user.

I have implemented it with a NavigationView on the left side bar and a second navigation view on the center document view and the left sidebar displayed in it.

And I have tried using a NavigationView around the left sidebar with HSplitview around the Document and right side view.

How do I get the window width adjustment to ONLY affect the document view, and the size of the sidebars to be adjustable by the User only, the way it works in XCode.

Here is the project on GitHub if anyone would like to look and make suggestions:





Maybe a clearer way to state this is - I want the user to be able to adjust the width of the rightside sidebar, and I do not want a change in the window width to affect it. The only document (center view) should expand or shrink in response to changes in the window width.

ANY suggestions will be appreciated.


Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Would you describe yourself as knowledgeable, but struggling when you have to come up with your own code? Fernando Olivares has a new book containing iOS rules you can immediately apply to your coding habits to see dramatic improvements, while also teaching applied programming fundamentals seen in refactored code from published apps.

Try the book!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.