Type Method

imageNamed:

Returns the image object associated with the specified filename.

Declaration

+ (UIImage *)imageNamed:(NSString *)name;

Parameters

name

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. For PNG images, you may omit the filename extension. For all other file formats, always include the filename extension.

Return Value

The image object for the specified file, or nil if the method could not find the specified image.

Discussion

This method looks in the system caches for an image object with the specified name and returns the variant of that image that is best suited for the main screen. If a matching image object is not already in the cache, this method locates and loads the image data from disk or from an available asset catalog, and then returns the resulting object.

The system may purge cached image data at any time to free up memory. Purging occurs only for images that are in the cache but are not currently being used.

In iOS 9 and later, this method is thread safe.

Special Considerations

If you have an image file that will only be displayed once and wish to ensure that it does not get added to the system’s cache, you should instead create your image using imageWithContentsOfFile:. This will keep your single-use image out of the system image cache, potentially improving the memory use characteristics of your app.

See Also

Loading and Caching Images

imageNamed:inBundle:compatibleWithTraitCollection:

Returns the named image that is also compatible with the specified trait collection.