UIImage image = [UIImage imageNamed:imageFileName]; api
這種圖片加載方式帶有圖片緩存的功能,使用這種方式加載圖片後,圖片會自動加入系統緩存中,並不會當即釋放到內存。一些資源使程序中常常使用的圖片資源, 緩存
使用這種方式會加快程序的運行減小IO操做,但對於項目中只用到一次的圖片,若是採用這種方案加載,會增致使程序的內存使用增長。 app
如下爲官方對此方法的解釋說明: this
Returns the image object associated with the specified filename. spa
The name of the file. If this is the first time the image is being loaded, the method looks for an image with the specified name in the application’s main bundle. 圖片
The image object for the specified file, or nil if the method could not find the specified image. 內存
This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already ci
in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object. 資源
+ (UIImage *)imageWithContentsOfFile:(NSString *)path it
+ (UIImage *)imageWithData:(NSData *)data
圖片資源反覆使用到,如按鈕背景圖片的藍色背景,這些圖片要常常用到,並且佔用內存少
(1)圖片通常只使用一次,如一些用戶的照片資源
(2)圖片資源較大,加載到內存後,比較耗費內存資源