Forked from marteinn/progamatically-popover-example.m
Created
January 12, 2022 17:36
-
-
Save PaulMcClernan/ffe7e4efb8b8d6880311816dc14330e9 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment