imageNamed 与 imageWithContentsOfFile 区别

Use the imageNamed:inBundle:compatibleWithTraitCollection: method (or the imageNamed: method) to create an image from an image asset or image file located in your app’s main bundle (or some other known bundle). Because these methods cache the image data automatically, they are especially recommended for images that you use frequently.
Use the imageWithContentsOfFile: or initWithContentsOfFile: method to create an image object where the initial data is not in a bundle. These methods load the image data from disk each time, so you should not use them to load the same image repeatedly.

来自:https://developer.apple.com/documentation/uikit/uiimage?language=objc

小结

imageNamed 只适合用于小的图片的读取,或重复使用一张图片的时候,而当加载一些比较大的图片文件的时候,我们应当尽量避免使用这个方法.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章