adding menu item with image to main menu?
adding menu item with image to main menu?
- Subject: adding menu item with image to main menu?
- From: email@hidden
- Date: Fri, 03 Oct 2003 12:08:23 -0700 (PDT)
Hello,
I would like to add an item to the main menu of my app and have it represented
by an image, not text. I have tried using:
// get image
NSImage *scriptIcon = [NSImage imageNamed: @"script"];
[scriptIcon setScalesWhenResized: YES];
[scriptIcon setSize: NSMakeSize(16, 16)];
// create menu item with no title and set image
NSMenuItem *scriptMenuItem = [[NSMenuItem alloc] initWithTitle: @"" action:
nil keyEquivalent: @""];
[scriptMenuItem setImage: scriptIcon];
// create submenu
NSMenu *scriptMenu = [[NSMenu alloc] initWithTitle: @"Script"];
[scriptMenuItem setSubmenu: scriptMenu];
[scriptMenu release];
// add new menu item
[[NSApp mainMenu] addItem: scriptMenuItem];
[scriptMenuItem release];
However, this puts the name of the menu ("Script") into the main menu bar. The
image is not displayed either.
Does anyone know how to add a menu item to the main menu represented by an
image? Is this supported? I don't want to use NSStatusItem since that will be
put on the right side of the menu bar and will be visible even if my app is not
the active app.
Thanks,
Ujwal
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.