Set NSWindow Size programmatically

前端 未结 6 2063
栀梦
栀梦 2021-02-01 19:19

How can I set the window size programmatically? I have a window in IB and I want to set the size of it in my code to make it larger.

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 20:15

    my two cents for swift 4.x 7 OSX:

    a) do not call on viewDidLoad b) go on main queue... b) wait some time... so for example use:

    private final func setSize(){
        if let w = self.view.window{
            var frame = w.frame
            frame.size = NSSize(width: 400, height: 800)
            w.setFrame(frame, display: true, animate: true)
    
        }
    }
    

提交回复
热议问题