Set Window Resizable

Cristian picture Cristian · May 6, 2012 · Viewed 12k times · Source

In IB this can be done easily by checking the 'Resize' checkbox on or off. My problem is I want my main NSWindow to not be resizable, until a button is clicked, and then i want it to be resizable.

I've scoured the Internet but can't find anything? Can a window not be made to be resizable or not programmatically?

Thanks in advance everyone!

Answer

Ken Thomases picture Ken Thomases · May 6, 2012

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