Frantic
Frantic

Reputation: 1179

Cocoa auto-resizable window

How can I make my NSWindow with NSTabView smoothly resize when user clicks a tab? I want it to like "System Preferances" application: window changes its size according to content.

Upvotes: 3

Views: 2336

Answers (1)

ughoavgfhw
ughoavgfhw

Reputation: 39925

Use NSWindow's setFrame:animated: method. If you want to resize the window down, make sure you decrease the y coordinate of the origin by the same amount you increase the size of the window. To also resize the views in the window, make sure you set up their autoresizing properties correctly.

NSWindow *window;
CGFloat widthChange, heightChange;

NSRect frame = [window frame];
frame.size.width += widthChange;
frame.size.height += heightChange;
frame.origin.y -= heightChange;
[window setFrame:frame animated:YES];

Upvotes: 7

Related Questions