Add a menu item


/ Published in: Objective C
Save to your folder(s)

Programmatically add a menu item


Copy this code and paste it in your HTML
  1. // Beware: the keyEquivalent must be lowercase in order not to have the shift modifier
  2. NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Action" action:@selector(menuItemAction:) keyEquivalent:@"r"];
  3. [menuItem setTarget:self];
  4. [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask];
  5. // Add the menu item at the end of menu whose index is 1 (most probably the File menu)
  6. [[[[NSApp mainMenu] itemAtIndex:1] submenu] addItem:menuItem];

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.