Making Window Hug Its Contents in SwiftUI on macOS
I recently ran into a problem in Cork: I wanted to open a new window, which would always hug its contents, meaning it would always be precisely the size of the content.
I was willing to sacrifice resizability, since this particular window didn’t really need it (it was a custom About panel).
What You Need to Do
In order to accomplish this, you need to set .windowResizability
to .contentSize
. In the end, you’ll end up with code like this:
Window("About", id: .aboutWindowID)
{
AboutView()
}
.windowResizability(.contentSize)