Forked from marteinn/progamatically-popover-example.m
Created
February 1, 2018 13:58
-
-
Save IndrekV/dfe78adf74e4339254429a404289d231 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 hidden or 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