1、imageNamed
imageNamed的優點是可以將已經加載過的圖片緩存到內存中。蘋果的文檔中有如下說法:
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 in the cache, this method locates and loads the image data from disk or asset catelog, and then returns the resulting object. You can not assume that this method is thread safe.
這個方法根據圖片名稱會先在系統緩存中尋找圖片。如果緩存中沒有這個圖片對象,這個方法會從指定的文件中尋找對應的圖片,并將其緩存到內存中。
當你需要重復使用一張圖片的時,比如UITableView里的cell需要重復加載一張圖片時
2、imageWithContentsOfFile或者imageWithData
這個方法只是簡單的加載圖片,并不會緩存到內存中。圖片會以數據加載到程序中
當不需要重用圖片,或者是下載一個很大圖片等可以使用該方法
系統不會浪費內存。