差异b/w imageNamed和imageWithContentsOfFile

Gra*_*ell 4 iphone objective-c uiimage ios

ObjectiveC中b/w imageNamedimageWithContentsOfFile有什么区别

Ale*_*lex 18

imageNamed: imageNamed cache是​​你的图像,你失去了对内存的控制 - 不能保证释放对象实际上会释放图像,但是在缓存时第二次提供更快的图像加载.如果您使用的是Interface Builder,并在"图像视图属性"中设置图像,那么它也等于imageNamed方法.应用程序运行时,图像将立即缓存

imageWithContentsOfFile: imageWithContentsOfFile不缓存图像并且更加内存友好,但因为它不缓存图像并且加载速度要慢得多.imageWithContentsOfFile:要求您输入完整路径.我不明白为什么imageNamed:不会被推荐,除了你无法访问应用程序包之外的文件.