Wednesday, December 15, 2010

Using filename extension with the UIImage imageNamed method

From iOS 4 you are not required to specify the filename extension when using UIImage, that is, you can set the image like this:

UIImage *testImage = [UIImage imageNamed: "anImageWithoutExt"];

and UIImage will figure out what to use from what ever is present in the bundle.

However, if your deployment target is older than iOS4 then your UIImage doesn't load the resource and so returns nil when the app is run on pre-iOS4.

Recommendation: use a filename extension if you deployment target OS is below iOS 4.

No comments: