黑白差异imageNamed和imageWithContentsOfFile [英] Difference b/w imageNamed and imageWithContentsOfFile

查看:64
本文介绍了黑白差异imageNamed和imageWithContentsOfFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ObjectiveC中,黑白 imageNamed imageWithContentsOfFile 有什么区别

What is the difference b/w imageNamed and imageWithContentsOfFile in ObjectiveC

推荐答案

imageNamed: imageNamed缓存会缓存您的图片,您将失去对内存的控制权-无法保证释放对象实际上会释放图片,但是在缓存时确实提供了第二次更快的图片加载速度.如果您使用的是Interface Builder,并且在图像视图属性"中设置图像,那也等于imageNamed方法.应用运行后,图像将立即被缓存

imageNamed: imageNamed cache’s your images and you lose control over the memory - there's no guarantee that releasing the object will actually release the image but does provide faster loading of images second time around as they are cached. If you are using Interface Builder, and setting the image in Image View Attributes, that is also equal to imageNamed method. The image will be cached immediately when the app is ran

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

imageWithContentsOfFile : imageWithContentsOfFile does not cache images and is more memory friendly however as it does not cache images and they are loaded much slower. imageWithContentsOfFile: requires you to put the full path. I don't see why imageNamed: wouldn't be recommended, besides the fact that you can't access files outside of the application bundle.

这篇关于黑白差异imageNamed和imageWithContentsOfFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆