amone
amone

Reputation: 3862

Set initial size for NSWindow

I'm trying to set an initial size for my NSWindow. First, I tried to set size using storyboard.

enter image description here

And then I tried the code below, the both don't work.

NSWindow *mainWindow = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
mainWindow.titleVisibility=NSWindowTitleHidden;
NSRect frame = mainWindow.frame;
frame.size=CGSizeMake(1000, 200);
[mainWindow setFrame:frame display:YES];

I tried to check or uncheck the "Restorable" attribute. How can I set an initial size for NSWindow? Why are these not working?

Upvotes: 6

Views: 3885

Answers (2)

Ely
Ely

Reputation: 9121

If you use a storyboard with macOS 10.15.5 or newer, the initial size of the NSWindow may be result of the sum of all containing NSView objects in the contentViewController. This may result in a larger window than in earlier macOS versions.

To fix unexpected large window sizes, search for large NSView objects in your storyboard, and make them smaller. Keep resizing and testing until the initial window size is to your liking.

Upvotes: 0

Rene Blath
Rene Blath

Reputation: 41

I found a way to set the initial window size in the storyboard editor of Xcode. Instead of setting the size of the window, you need to set it on the ViewControllers first element like this:

enter image description here

Upvotes: 4

Related Questions