Reputation: 55
In objective C, I'm trying to resize an application window after a button is clicked. If the window was 200x200, a (+) button is pressed to make it 200x210 or the (-) button is pressed to make it 200x190.
I'm just not sure how to set the size of windows after they're made in the editor.
Don't have sample code because it's simple and I'm not sure where to start.
Upvotes: 1
Views: 2224
Reputation: 33379
Here you go:
- (IBAction)plusButtonClicked:(NSControl *)sender
{
NSRect frame = sender.window.frame;
frame.size.height += 20;
[sender.window setFrame:frame display:YES animate:YES];
}
Depending whether you want the top or bottom of the window to expand, you may also need:
frame.origin.y -= 20;
Upvotes: 2
Reputation: 104092
Have a look at setFrame:display: in the NSWindow Class Reference.
Upvotes: 0