How to enable / disable the zoom button (green + button)?

I am new to Mac OSx / Cocoa. During the creation of my first application, I came across several things, and one of them is my problem with the green + button, which is designed to scale.

I would like to know if it is possible to dynamically set the behavior of the zoom button of the application window? Am I breaking any rule from Apple’s principles?

I want to specify the behavior of the button according to a specific user. Let's say the user is allowed to have a zoom button, then the button must be enabled; otherwise, leave the button disabled.

In this case, when the application is running, I check if the user is allowed to have the zoom button turned on. From here I want to customize the behavior of the window related to the zoom button - whether to enable or disable it in accordance with a preliminary check of the user mode.

Thanks for the help!

+7
source share
3 answers

You can get a link to this button using standardWindowButton:NSWindowZoomButton , and then do everything you can do with any NSButton .

Update (fast):

 var button = view.window?.standardWindowButton(NSWindowButton.ZoomButton) button?.enabled = false 
+9
source

Button capture and setting turned on are not ideal. The best way (10.6+) is to use setStyleMask: Here's how to do it:

 window.styleMask = NSTitledWindowMask | NSClosableWindowMask 

You can add or remove styles as you wish. Another way to do this without changing the style is to set minSize and maxSize to the same size. This will also disable resizing.

+6
source

In Swift 3, this is the easiest way to remove this feature:

 var style = window.styleMask style.remove(.resizable) window.styleMask = style 

I usually do this in viewDidAppear for view controllers in storyboards that automatically create a window controller for them, instead of the one I can talk to.

+1
source

All Articles