Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI window size for document based MacOs App

Tags:

swiftui

I am moving my app from SwiftUI xCode 11 to the new Document Based App lifecycle format in xCode 12. I have not been able to figure out how to set the window size. In Xcode 11 I had

window = NSWindow(
            contentRect: NSRect(x: 0, y: 0, width: 1200, height: 800),
            styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
            backing: .buffered, defer: false)

How do I achieve the same effect with no AppDelegate?

like image 705
ramnefors Avatar asked Nov 06 '22 06:11

ramnefors


1 Answers

Try the following (as window by default has .fullSizeContentView)

var body: some Scene {
    WindowGroup {
        ContentView()
          .frame(width: 1200, height: 800)    // << here !!
          .frame(minWidth: 800, maxWidth: .infinity, 
               minHeight: 600, maxHeight: .infinity)
    }
}
like image 166
Asperi Avatar answered Dec 16 '22 12:12

Asperi