• 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: Loading an image contained in a custom framework ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading an image contained in a custom framework ?


  • Subject: Re: Loading an image contained in a custom framework ?
  • From: j o a r <email@hidden>
  • Date: Fri, 26 Aug 2005 23:34:42 +0200


On 26 aug 2005, at 23.04, Eric Morand wrote:

What is the dedicated method to load an image that is NOT included in the main bundle ?

I've done it in this very convoluted way for one of my frameworks. It's not a complete drop-in replacement for "+[NSImage imageNamed:]", but it should get the job done.


h-file=====================================================

@interface NSImage (NSImage_Additions)

+ (id) imageWithFileName:(NSString *) fileName inBundleForClass: (Class) aClass;
+ (id) imageInFrameworkWithFileName:(NSString *) fileName;


@end

m-file=====================================================

@interface DummyClass : NSObject
@end
@implementation DummyClass
@end

@implementation NSImage (NSImage_Additions)

+ (id) imageWithFileName:(NSString *) fileName inBundle:(NSBundle *) aBundle
{
NSImage *img = nil;


if (aBundle != nil)
{
NSString *imagePath;
if ((imagePath = [aBundle pathForResource: fileName ofType: nil]) != nil)
{
img = [[[NSImage alloc] initWithContentsOfFile: imagePath] autorelease];
}
}


    return img;
}

+ (id) imageWithFileName:(NSString *) fileName inBundleForClass: (Class) aClass
{
return [self imageWithFileName: fileName inBundle: [NSBundle bundleForClass: aClass]];
}


+ (id) imageInFrameworkWithFileName:(NSString *) fileName
{
    NSBundle *aBundle = [NSBundle bundleForClass: [DummyClass class]];
    return [self imageWithFileName: fileName inBundle: aBundle];
}

@end

=====================================================

j o a r


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

References: 
 >Loading an image contained in a custom framework ? (From: Eric Morand <email@hidden>)

  • Prev by Date: Re: Loading an image contained in a custom framework ?
  • Next by Date: AppleScript Incorporation Woes
  • Previous by thread: Re: Loading an image contained in a custom framework ?
  • Next by thread: Beginning custom view question
  • Index(es):
    • Date
    • Thread