SwiftUI – How to disable window resizability in macOS 11 and 12

My app needs to run on macOS 11+. It has one window of fixed size i.e. it should NOT be resizable.

.windowResizability(.contentSize) is only available in macOS 13+.

How can window resizability be disabled in macOS 11 and 12 ?

I'm running Xcode 16.2 on macOS 15.3.2.

Thanks.

Answered by B347 in 829392022

Hi, did you check with this: I know its AppKit based, but you can mix&match both Frameworks.

[https://developer.apple.com/documentation/appkit/nswindow/stylemask-swift.property)

[https://developer.apple.com/documentation/appkit/nswindow/stylemask-swift.struct)

if let window = NSApplication.shared.windows.first {
    window.styleMask.remove(.resizable)
    window.setContentSize(NSSize(
        width: 400, 
        height: 400)
    )
}
Accepted Answer

Hi, did you check with this: I know its AppKit based, but you can mix&match both Frameworks.

[https://developer.apple.com/documentation/appkit/nswindow/stylemask-swift.property)

[https://developer.apple.com/documentation/appkit/nswindow/stylemask-swift.struct)

if let window = NSApplication.shared.windows.first {
    window.styleMask.remove(.resizable)
    window.setContentSize(NSSize(
        width: 400, 
        height: 400)
    )
}

B347, many thanks.

Yes, I did try stylemask but tried different forms:

  • .styleMask.subtract(.resizable)
  • NSWindow.styleMask.remove(.resizable)
  • Window.styleMask.remove(.resizable)

Naturally, all my attempts resulted in errors.

My app doesn't import AppKit as yet so, I'll just restrict it to running on macOS 13+.

It's very early days for me.

SwiftUI – How to disable window resizability in macOS 11 and 12
 
 
Q