-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUIImage+TBL.m
27 lines (24 loc) · 1.02 KB
/
UIImage+TBL.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#import "UIImage+TBL.h"
@implementation UIImage (TBL)
+(UIImage *)imageNamed:(NSString *)name ofType:(NSString *)type shouldCache:(BOOL)cache {
if (cache) return [self imageNamed:name];
UIImage *image = nil;
NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:type];
if (path != nil) {
image = [UIImage imageWithContentsOfFile:path];
#ifdef DEBUG
// Images in xcassets will not be found by poking around in the mainBundle.
// shouldCache:NO does not work for images in xcassets and will always
// return nil.
if (!image) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:[NSString stringWithFormat:@"Image not found. If the image is in xcassets you must pass shouldCache:YES or use the default [UIImage imageNamed:] method."]
userInfo:nil];
}
#endif
} else {
image = [self imageNamed:name];
}
return image;
}
@end