在iOS开发中生成一个UIImage对象的方法通常有两种
1.利用imageNamed方法
2.使用imageWithContentsOfFile
下面介绍这两中方法的区别:
imageNamed,从应用bundle中寻找图片加载到cache中,适用于图片较小或经常使用。加载图片太大容易产生内存泄漏。
imageWithContentsOfFile:
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
UIImage *image = [UIImage imageWithContentsOfFile:filePath];