设置窗口的最小和最大大小

时间:2011-04-26 19:35:18

标签: objective-c cocoa macos window

如何使用Objective-C库设置OS X中窗口的最大和最小大小?

2 个答案:

答案 0 :(得分:10)

[theWindow setMaxSize:windowMaxSize];
[theWindow setMinSize:windowMinSize];

NSWindow Class Reference

答案 1 :(得分:5)

在Swift 2中,这将是:

myWindow.contentMinSize = NSSize(width: 600, height: 500)
myWindow.contentMaxSize = NSSize(width: 1024, height: 780)

同样根据Apple文档,contentMinSize优先于setMaxSize。

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/index.html#//apple_ref/occ/instp/NSWindow/contentMaxSize