Skip to content

Commit

Permalink
Merge pull request #30 from Dschee/feature/different-bundle
Browse files Browse the repository at this point in the history
Added support for loading files from different bundles (than mainBundle)
  • Loading branch information
jmenter committed Nov 23, 2015
2 parents d6e0632 + d18be25 commit 31617be
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions Classes/JAMSVGImage/SVG Image/JAMSVGImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

/** Initializes a new SVG image from a file or data source. */
+ (JAMSVGImage *)imageNamed:(NSString *)name;
+ (JAMSVGImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle;
+ (JAMSVGImage *)imageWithContentsOfFile:(NSString *)path;
+ (JAMSVGImage *)imageWithSVGData:(NSData *)svgData;

Expand Down
17 changes: 11 additions & 6 deletions Classes/JAMSVGImage/SVG Image/JAMSVGImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,22 @@ - (void)encodeWithCoder:(NSCoder *)aCoder;

+ (JAMSVGImage *)imageNamed:(NSString *)name;
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
imageCache = [[NSCache alloc] init];
});

NSBundle *bundle;
#if !TARGET_INTERFACE_BUILDER
bundle = NSBundle.mainBundle;
#else
bundle = [NSBundle bundleForClass:self.class];
#endif
return [self imageNamed:name inBundle:bundle];
}

+ (JAMSVGImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
imageCache = [[NSCache alloc] init];
});

NSString *fileName = [bundle pathForResource:name ofType:@"svg"];
if (!fileName) {
fileName = [bundle pathForResource:name ofType:@"svgz"];
Expand All @@ -71,7 +76,7 @@ + (JAMSVGImage *)imageNamed:(NSString *)name;
image = [JAMSVGImage imageWithContentsOfFile:fileName];
[imageCache setObject:image forKey:fileName];
}

return image;
}

Expand Down
1 change: 1 addition & 0 deletions Classes/JAMSVGImage/SVG Image/UIImage+SVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@interface UIImage (SVG)

+ (UIImage *)imageFromSVGNamed:(NSString *)svgName;
+ (UIImage *)imageFromSVGNamed:(NSString *)svgName inBundle:(NSBundle *)bundle;
+ (UIImage *)imageFromSVGNamed:(NSString *)svgName atSize:(CGSize)size;
+ (UIImage *)imageFromSVGNamed:(NSString *)svgName atScale:(CGFloat)scale;

Expand Down
5 changes: 5 additions & 0 deletions Classes/JAMSVGImage/SVG Image/UIImage+SVG.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ + (UIImage *)imageFromSVGNamed:(NSString *)svgName;
return [JAMSVGImage imageNamed:svgName].image;
}

+ (UIImage *)imageFromSVGNamed:(NSString *)svgName inBundle:(NSBundle *)bundle
{
return [JAMSVGImage imageNamed:svgName inBundle:bundle].image;
}

+ (UIImage *)imageFromSVGNamed:(NSString *)svgName atSize:(CGSize)size;
{
return [[JAMSVGImage imageNamed:svgName] imageAtSize:size];
Expand Down

0 comments on commit 31617be

Please sign in to comment.