• 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
Re: Dock Icon Help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
  • Follow-Ups:
    • Re: Dock Icon Help
      • From: j o a r <email@hidden>
References: 
 >Re: Dock Icon Help (From: j o a r <email@hidden>)

  • Prev by Date: Tutoring #2
  • Next by Date: Re: When to use Java with Cocoa
  • Previous by thread: Re: Dock Icon Help
  • Next by thread: Re: Dock Icon Help
  • Index(es):
    • Date
    • Thread