UIImage imageNamed和UIImage imageWithContentsOfFile区别

 

UIImage imageNamed和

[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:nil]];

 

NSString *path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"png"];
myImage = [UIImage imageWithContentsOfFile:path];

用xib创建的UIImage  都是 通过imageNamed来创建的

 总结:

这两个方法各有利弊, 

 

1. imageNamed用这个方法,内存不会清理的, 但是内存消耗小,

2. 第二个内存会清理, 但是内存消耗大, 

 在图片多或者图片大, 并且比较少用的页面, 我们使用

[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:nil]];

 

常用的页面, 我们都是用imageNamed

posted @ 2014-11-28 17:08  apem  阅读(160)  评论(0编辑  收藏  举报