diff --git a/Classes/JAMSVGImage/SVG Image/JAMSVGImage.h b/Classes/JAMSVGImage/SVG Image/JAMSVGImage.h index 310153d..26e15f4 100644 --- a/Classes/JAMSVGImage/SVG Image/JAMSVGImage.h +++ b/Classes/JAMSVGImage/SVG Image/JAMSVGImage.h @@ -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; diff --git a/Classes/JAMSVGImage/SVG Image/JAMSVGImage.m b/Classes/JAMSVGImage/SVG Image/JAMSVGImage.m index af789fd..fee8de9 100644 --- a/Classes/JAMSVGImage/SVG Image/JAMSVGImage.m +++ b/Classes/JAMSVGImage/SVG Image/JAMSVGImage.m @@ -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"]; @@ -71,7 +76,7 @@ + (JAMSVGImage *)imageNamed:(NSString *)name; image = [JAMSVGImage imageWithContentsOfFile:fileName]; [imageCache setObject:image forKey:fileName]; } - + return image; } diff --git a/Classes/JAMSVGImage/SVG Image/UIImage+SVG.h b/Classes/JAMSVGImage/SVG Image/UIImage+SVG.h index 433a4b0..c32f4f5 100644 --- a/Classes/JAMSVGImage/SVG Image/UIImage+SVG.h +++ b/Classes/JAMSVGImage/SVG Image/UIImage+SVG.h @@ -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; diff --git a/Classes/JAMSVGImage/SVG Image/UIImage+SVG.m b/Classes/JAMSVGImage/SVG Image/UIImage+SVG.m index 622ea4a..ae57f96 100644 --- a/Classes/JAMSVGImage/SVG Image/UIImage+SVG.m +++ b/Classes/JAMSVGImage/SVG Image/UIImage+SVG.m @@ -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];