Set NSWindow Size programmatically

前端 未结 6 2167
栀梦
栀梦 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:07

    It is actually seems that +/- need to be reversed to keep window from moving on the screen:

    NSRect frame = [window frame];
    frame.origin.y += frame.size.height; // origin.y is top Y coordinate now
    frame.origin.y -= theSizeYouWant.height; // new Y coordinate for the origin
    frame.size = theSizeYouWant;
    

提交回复
热议问题