Set Window Resizable
You can't change the style mask of a window after creating it, but you can set the window's minimum and maximum frame size to the same size. Do that after you and your resizable window awake from nib, and then change the maximum and optionally the minimum size back when the user clicks the button.
Since 10.6, you can change the style mask of a window using -[NSWindow setStyleMask:]
. So, you'd do something like this:
In Objective-C
To make it resizable:
window.styleMask |= NSWindowStyleMaskResizable;
To make it non-resizable:
window.styleMask &= ~NSWindowStyleMaskResizable;
In Swift
To make it resizable:
mainWindow.styleMask = mainWindow.styleMask | NSWindowStyleMaskResizable
To make it non-resizable:
mainWindow.styleMask = mainWindow.styleMask & ~NSWindowStyleMaskResizable
The Swift 3 solution to this issue is to use the OptionSet
class described at:
https://developer.apple.com/reference/swift/optionset
In short:
To replace the set of flags, you now do something like:
myWindow.styleMask = [ .resizable, .titled, .closable ]
To add a flag, do something like:
myWindow.styleMask.insert( [ .miniaturizable, .fullscreen ] )
To remove a flag, something like:
myWindow.styleMask.remove( [ .resizable ] )