Last active
January 15, 2022 12:13
-
-
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
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
Swift ➕1