在ios中图片加载有多种方式,常见的有[UIImage imageName:@"test.png"],和直接通过文件路径读取图片。前者会在cache中做缓存,后者不会做缓存。如果图片不是经常用的话建议还是用后者,ios应用程序的内存很宝贵。
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
NSData *image = [NSData dataWithContentsOfFile:filePath];
[UIImage imageWithData:image];
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"jpg"];
[UIImage imageWithContentsOfFile:aImagePath];
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
NSData *image = [NSData dataWithContentsOfFile:filePath];
[UIImage imageWithData:image];
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"jpg"];
[UIImage imageWithContentsOfFile:aImagePath];