Skip to content

Instantly share code, notes, and snippets.

@itfrombit
Created December 7, 2014 23:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itfrombit/2075934dabf9a378b628 to your computer and use it in GitHub Desktop.
Save itfrombit/2075934dabf9a378b628 to your computer and use it in GitHub Desktop.
excerpt to programmatically create a menu in OS X
NSMenu* menubar = [NSMenu new];
NSMenuItem* appMenuItem = [NSMenuItem new];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
NSMenu* appMenu = [NSMenu new];
NSString* toggleFullScreenTitle = @"Toggle Full Screen";
NSMenuItem* toggleFullScreenMenuItem = [[NSMenuItem alloc] initWithTitle:toggleFullScreenTitle
action:@selector(toggleFullScreen:)
keyEquivalent:@"f"];
[appMenu addItem:toggleFullScreenMenuItem];
NSString* quitTitle = [@"Quit " stringByAppendingString:appName];
NSMenuItem* quitMenuItem = [[NSMenuItem alloc] initWithTitle:quitTitle
action:@selector(terminate:)
keyEquivalent:@"q"];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment