dafi
dafi

Reputation: 3532

Cocoa How to set max window height but leave width free

I've a window that can be resized in width but has a fixed height, it sounds an easy task but I've an hardcoded value that I really hate.

My code is

NSWindow* win = ...;
NSSize maxSize = [win maxSize];
maxSize.width = 30000;
[win setMaxSize: maxSize];

How can I write this code to work with a system default?

If my approach is totally wrong how can I set the max window's size for only one dimension (width or height) leaving the other free?

Upvotes: 3

Views: 2158

Answers (1)

ebany
ebany

Reputation: 306

Maybe you could try to implement something like:

- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize {
    proposedFrameSize.height = window.frame.size.height;
    return proposedFrameSize;
}

Upvotes: 6

Related Questions