Skip to content

Instantly share code, notes, and snippets.

@marteinn
Last active January 15, 2022 12:13
Show Gist options
  • Save marteinn/d4842e3d404d6bac489c to your computer and use it in GitHub Desktop.
Save marteinn/d4842e3d404d6bac489c to your computer and use it in GitHub Desktop.
NSPopover Example: Create and show a NSPopover programmatically when a user clicks a button in a subview
-(void) buttonClick:(NSButton *)sender {
// Create view controller
EXPopoverViewController *viewController = [[EXPopoverViewController alloc] init];
// Create popover
NSPopover *entryPopover = [[NSPopover alloc] init];
[entryPopover setContentSize:NSMakeSize(200.0, 200.0)];
[entryPopover setBehavior:NSPopoverBehaviorTransient];
[entryPopover setAnimates:YES];
[entryPopover setContentViewController:viewController];
// Convert point to main window coordinates
NSRect entryRect = [sender convertRect:sender.bounds
toView:[[NSApp mainWindow] contentView]];
// Show popover
[entryPopover showRelativeToRect:entryRect
ofView:[[NSApp mainWindow] contentView]
preferredEdge:NSMinYEdge];
}
@mikeumus
Copy link

mikeumus commented Sep 21, 2020

Swift ➕1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment