Post

Replies

Boosts

Views

Activity

Reply to SwiftUI window aspect ratio
Here's another good one that would work better with multiple windows: Use a NSViewRepresentable to get binding for NSWindow as in this StackOverflow answer: https://stackoverflow.com/a/63439982 And in order for contentAspectRatio to exclude the title bar, you must also call window.styleMask.remove(.fullSizeContentView) Ending up with something like: struct Example: App { @State private var window: NSWindow? var body: some Scene { WindowGroup { ContentView() .background(WindowAccessor(window: $window)) .onChange(of: window) { newWindow in newWindow?.styleMask.remove(.fullSizeContentView) // Exclude title bar from content area newWindow?.contentAspectRatio = desiredAspectRatio } } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Dec ’22
Reply to SwiftUI window aspect ratio
I've tried setting contentAspectRatio from SwiftUI via NSApplication.shared.keyWindow?.contentAspectRatio = ratio which might be an acceptable hack for me -- but it looks like it's behaving more like aspectRatio, where the window title is included in the titlebar. Not sure how to get the aspect ratio to only limit the SwiftUI content.
Topic: UI Frameworks SubTopic: AppKit Tags:
Dec ’22