Set NSWindow Size programmatically

前端 未结 6 2130
栀梦
栀梦 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条回答
  •  萌比男神i
    2021-02-01 20:13

    Usually I want to resize the window based on the size of the content (not including the title bar):

    var rect = window.contentRect(forFrameRect: window.frame)
    rect.size = myKnownContentSize
    let frame = window.frameRect(forContentRect: rect)
    window.setFrame(frame, display: true, animate: true)
    

提交回复
热议问题