标签:load init off append nil undle ret loaded mat
+ (UIImage *)imageNamed:(NSString *)name ofBundle:(NSString *)bundleName {
static NSMutableDictionary *loadedObjectDict = nil;
if (!loadedObjectDict) {
loadedObjectDict = [[NSMutableDictionary alloc] init];
}
NSString *keyString = [NSString stringWithFormat:@"%@%@", bundleName, name];
RCDLiveWeakRef *ref = loadedObjectDict[keyString];
if (ref.weakRef) {
return ref.weakRef;
}
UIImage *image = nil;
NSString *image_name = [NSString stringWithFormat:@"%@.png", name];
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *bundlePath = [resourcePath stringByAppendingPathComponent:bundleName];
NSString *image_path = [bundlePath stringByAppendingPathComponent:image_name];
// NSString* path = [[[[NSBundle mainBundle] resourcePath]
// stringByAppendingPathComponent:bundleName]stringByAppendingPathComponent:[NSString
// stringWithFormat:@"%@.png",name]];
// image = [UIImage imageWithContentsOfFile:image_path];
image = [[UIImage alloc] initWithContentsOfFile:image_path];
[loadedObjectDict setObject:[RCDLiveWeakRef refWithObject:image] forKey:keyString];
return image;
}
标签:load init off append nil undle ret loaded mat
原文地址:http://www.cnblogs.com/lsh1234/p/6534419.html