IOS 本地图片加载


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

NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];

UIImage *image = [UIImage imageWithContentsOfFile:filePath];

使用时稍微麻烦一点,以文件数据形式被加载。返回的对象不会保存在缓存中,一旦对象销毁就会释放内存。

猜你喜欢

转载自blog.csdn.net/ws_752958369/article/details/80477150