Non-resizable window swift

后端 未结 5 462
无人及你
无人及你 2020-12-09 18:48

I have a NSViewController named Hardness, and I need not to let user resize it. Of course, I can just resize it back every time the users tries, bu

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 19:42

    This answer may be of some help in addition to the current one. There's also a nice simple way to accomplish this by using setHidden with NSWindowZoomButton

    Setup the functionality as a sub-class of NSWindow:

    Objective-C

    #import "CustomWindow.h"
    
    @implementation CustomWindow
    
    - (void)awakeFromNib {
    
    NSButton *zoomButton = [self standardWindowButton:NSWindowZoomButton];
    [zoomButton setHidden:YES];
    
    }
    
    @end
    

    Swift

    import CustomWindow
    
    class CustomWindow {
    
        func awakeFromNib() {
            var zoomButton: NSButton = self.standardWindowButton(NSWindowZoomButton)
            zoomButton.setHidden(true)
        }
    }
    

    Connect the custom class to your window in IB and the Zoom button should be now hidden!

提交回复
热议问题