imageNamed:
Returns the image object associated with the specified filename.
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.
Return Value of [UIImage imageNamed]
The image object for the specified file, or
nil
if the method could not find the specified image.Discussion of [UIImage 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 loads the image data from the specified file, caches it, and then returns the resulting object.[UIImage imageNamed]
On a device running iOS 4 or later, the behavior is identical if the device’s screen has a scale of
1.0
. If the screen has a scale of 2.0
, this method first searches for an image file with the same filename with an @2x
suffix appended to it. For example, if the file’s name isbutton
, it first searches for button@2x
. If it finds a 2x, it loads that image and sets the scale
property of the returned UIImage
object to2.0
. Otherwise, it loads the unmodified filename and sets the scale
property to 1.0
. See iOS App Programming Guide for more information on supporting images with different scale factors.
Example of [UIImage imageNamed]
UIImage *testImage = [image setImage:[UIImage imageNamed:@"some.png"]];
UIImage *testImage2 = [image setImage:[UIImage imageNamed:@"some.jpg"]];