Re: Dock Icon Help
Re: Dock Icon Help
- Subject: Re: Dock Icon Help
- From: j o a r <email@hidden>
- Date: Sat, 10 May 2003 01:08:28 +0200
On Friday, May 9, 2003, at 19:54 Europe/Stockholm, Ryan Stevens wrote:
There's really no reason (that I can see) to avoid using +imageNamed
in favor of -initWithContentsOfFile unless you put the image in some
special place that +imageNamed can't find.
The reason I used the "initWithContents..." method in the last email
(as did the poster before me) is that it tries to create image reps
from the data immediately, while the "initByReferencing..." uses lazy
initialization. If you use "initWithContents..." it returns nil if no
image reps can be created from the image data - while using
"initByReferencing..." you cannot be sure that the image returned will
ever be able to create image reps from the data it was pointed to. Read
the docs for more info.
Since I'm not sure which init method "imageNamed:" uses internally, I
thought that it would be best to explicitly use the
"initWithContents..." when troubleshooting the problem that the guy who
started this thread had.
I like this (more compact) way..
While "compact" might be considered cool - it's not often the best way
to provide sample code on mailing lists, where it's better to be overly
clear of what you're trying to illustrate.
- (void)setDockIcon
{
NSImage *coolImage = [NSImage imageNamed:@"2d Marine Division"];
if (coolImage != nil) [NSApp setApplicationIconImage:coolImage];
else
NSLog(@"Failed to set the Dock icon. Woops!");
}
Also note that if you use "imageNamed:" you should specify the file
name including the file name suffix when creating an image from an
image file (and not just fetching a named image) - at least according
to the docs.
j o a r
_______________________________________________
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.