forked from barefoothackers/Barefoot-categories
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIImage+Barefoot.m
26 lines (23 loc) · 974 Bytes
/
UIImage+Barefoot.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
#import "UIImage+Barefoot.h"
@implementation UIImage (Barefoot)
+ (NSArray*)imagesFromBaseName:(NSString*)base withEnding:(NSString*)ending {
NSArray *resourceNames = [[NSBundle mainBundle] pathsForResourcesOfType:ending inDirectory:nil];
NSIndexSet *matchingImageIndexes = [resourceNames indexesOfObjectsPassingTest:^BOOL (id element, NSUInteger i, BOOL *stop) {
NSString *path = (NSString *)element;
NSString *imageName = [path lastPathComponent];
if ([imageName hasPrefix:base] && ![imageName hasSuffix:[NSString stringWithFormat:@"@2x%@",ending]]) {
return YES;
}
return NO;
}];
NSArray *imageNames = [resourceNames objectsAtIndexes:matchingImageIndexes];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:[imageNames count]];
for(NSString *imageName in imageNames) {
[images addObject:[UIImage imageNamed:[imageName lastPathComponent]]];
}
if ([images count] == 0) {
return nil;
}
return images;
}
@end