• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSMenu icon
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSMenu icon


  • Subject: NSMenu icon
  • From: John Nairn <email@hidden>
  • Date: Wed, 24 Dec 2008 13:11:39 -0800

I wanted to make one of the main menus be an icon (like the "Script" icon in many applications). I tried to due using Apple sample code (MenuItemView) and I can insert image in items, but not in the MenuItem used for the title. How is that done?

Here is the code. The first section creates item for the menu bar and adds it to the main menu. The second section adds one item to the menu. The image works for the item in the menu, but not for the display in the menu bar:

// create new menu from scratch trying to use an image
NSMenuItem* newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Custom Menu" action:NULL keyEquivalent:@""];
NSMenu* newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Custom"];
[newItem setEnabled:YES];
NSImageView *menuImage=[[NSImageView alloc] initWithFrame:NSMakeRect(0.,0.,16.,16.)];
[menuImage setImage:[[NSImage imageNamed:@"bar_image.tiff"] retain]];
[newItem setView: menuImage];
[newItem setSubmenu:newMenu];
[newMenu release];
[[NSApp mainMenu] insertItem:newItem atIndex:[[NSApp mainMenu] numberOfItems]-1];
[newItem release];

// insert image in the first item in the menu
newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Custom Item 1" action:@selector(menuItem1Action:) keyEquivalent:@""];
[newItem setEnabled:YES];
menuImage=[[NSImageView alloc] initWithFrame:NSMakeRect(0.,0.,32.,32.)];
[menuImage setImage:[[NSImage imageNamed:@"item_image.tiff"] retain]];
[newItem setView: menuImage];
[newItem setTarget:self];
[newMenu addItem:newItem];
[newItem release];


---------------
John Nairn
GEDitCOM - Genealogy Software for the Macintosh
http://www.geditcom.com


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSMenu icon
      • From: Ron Fleckner <email@hidden>
  • Prev by Date: Re: Network volume
  • Next by Date: Re: NSMenu icon
  • Previous by thread: Re: Messaging framework
  • Next by thread: Re: NSMenu icon
  • Index(es):
    • Date
    • Thread