Re: Dock Icon Help
Re: Dock Icon Help
- Subject: Re: Dock Icon Help
- From: Ryan Stevens <email@hidden>
- Date: Fri, 9 May 2003 10:54:32 -0700
On Friday, May 9, 2003, at 01:14 AM, j o a r wrote:
On Friday, May 9, 2003, at 09:42 Europe/Stockholm, Andreas Schempp
wrote:
Try to retain your image, before you use it.
Or do something like this:
NSImage* coolImage = [[NSImage alloc] init];
[coolImage initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"2d Marine Division" ofType:@"icns"]]
This is a pretty crappy suggestion... Why should he need to increase
the retain count of the image before handing it over? It's also
invalid use of ObjC - you cannot init an object multiple times! Better
version, with some logs added for troubleshooting purposes:
Kind of harsh but true. :/
NSString *imgPath = [[NSBundle mainBundle] pathForResource: @"ImgName"
ofType: @"tiff"]; // If it is in tiff...
if (imgPath != nil)
{
NSImage *img = [[[NSImage alloc] initWithContentsOfFile: imgPath]
autorelease];
if (img != nil)
{
[NSApp setApplicationIconImage: img];
}
else
{
NSLog(@"Could not create image");
}
}
else
{
NSLog(@"Could not locate image");
}
I like this (more compact) way..
- (void)setDockIcon
{
NSImage *coolImage = [NSImage imageNamed:@"2d Marine Division"];
if (coolImage != nil) [NSApp setApplicationIconImage:coolImage];
else
NSLog(@"Failed to set the Dock icon. Woops!");
}
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.
_______________________________________________
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.