Resize NSPopover after it is shown
Asked Answered
A

3

8

I have an NSPopover who's content in an NSView. I create the popover and add the view like this:

NSPopover *thePopover = [[NSPopover alloc] init];
[thePopover setContentViewController:myViewController];

I then show the popover and set the size:

[thePopover setContentSize:NSMakeSize(300.0f, 160.0f)];

At this point the popover is visible and its content view is correct. Is there a way that I can resize the popover at this point without closing and re-showing it?

Alphonso answered 22/1, 2013 at 1:1 Comment(0)
A
11

I was able to achieve this by calling back to the controller that launched the popover via a delegate protocol and resetting the size using the setContentSize:

Alphonso answered 22/1, 2013 at 23:53 Comment(1)
how did you do that?Excide
G
3

From the documentation:

The popover's content size is set to match the size of the content view when the content view controller is set.

So, set the frame of the popover's content view.

Gnathic answered 22/1, 2013 at 8:2 Comment(1)
This seems like the simplest answer.Hyacinthe
P
3

NSWindow has private property _popover that store a reference to NSPopover. You can use it to access to NSPopover instance from any NSViewController (and then call setContentSize: on it) like this:

- (NSPopover *)popover
{
    NSWindow *window = self.view.window;
    NSPopover *popover = [window valueForKey:@"_popover"];
    return popover;
}
Partida answered 29/4, 2015 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.