Re: Loading an image contained in a custom framework ?
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