Re: NSStatusItem:setImage - Icon not displaying (problem solved)
Re: NSStatusItem:setImage - Icon not displaying (problem solved)
- Subject: Re: NSStatusItem:setImage - Icon not displaying (problem solved)
- From: James Bush <email@hidden>
- Date: Wed, 3 Aug 2005 03:47:13 -0700
Solved this on a whim. Apparently, you must remove.png from the
resource path string:
OLD: pathForResource:@"image.png" ofType:@"png"]];
NEW: pathForResource:@"image" ofType:@"png"]];
In Apple's documentation:
"...the resource sought is identified by name, with no extension."
Now, how did I miss that?
__________________________________
On Aug 2, 2005, at 9:52 PM, James Bush wrote:
My application puts a menu (NSMenu) in the system status bar
(NSStatusBar). I can set the title of the menu to any string value
(NSStatusItem:setTitle), but cannot set the title to an image
(NSStatusItem:setImage). Here's the code:
- (void)awakeFromNib
{
NSImage *menuImage = [[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"image.png" ofType:@"png"]];
NSStatusBar *bar = [NSStatusBar systemStatusBar];
theItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[theItem retain];
[theItem setImage:menuImage];
[theItem setHighlightMode:YES];
[theItem setMenu:theMenu];
}
This code compiles without error or warning. When the build is run,
the menu can be displayed by clicking the location where the image
file should be.
The problem could be unrelated to the code, as well. For example:
1. Perhaps I've imported the image file into the project
incorrectly. Maybe it's not in the right location inside the
project folder or is in the wrong group. I cannot find decent
documentation on how to import images for use within your application.
2. Perhaps the image file is in the correct location in the project
folder (and in the right group), but the URL is not correctly
specified.
I'm tapped out on this one. None of the books I've bought, Apple's
documentation, Google and about 5 Cocoa Dev web sites have an
answer that works.
Thanks!
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden