美文网首页
UIImage的加载方式

UIImage的加载方式

作者: Kyniii | 来源:发表于2017-09-05 17:17 被阅读0次

第一种:

UIImage* image = [UIImage imageNamed:name];

第二种:

UIImage *image2 = [UIImage imageWithContentsOfFile:[[NSBundlemainBundle] pathForResource:@"image.png" ofType:nil]];

第三种:

NSData*imageData = [NSDatadataWithContentsOfFile:[[NSBundlemainBundle] pathForResource:@"image.png" ofType:nil]];

UIImage *image3 = [UIImage imageWithData:imageData];

总结:

如果图片很大并且并不经常使用,那么就不需要缓存这个图片。这种情况imageWithContentsOfFile比较合适,系统不会浪费内存来缓存图片。

然而,如果在程序中经常需要重用的图片,那么最好是选择imageNamed方法。

相关文章

网友评论

      本文标题:UIImage的加载方式

      本文链接:https://www.haomeiwen.com/subject/zyfpjxtx.html