tags:

views:

74

answers:

2

What is the best pattern for displaying images both on iOS3 and iOS4?

For example, here's code for a custom activity animation:

activityImageView.animationImages = [NSArray arrayWithObjects:  
[UIImage imageNamed:@"s01"],  
[UIImage imageNamed:@"s02"],  
[UIImage imageNamed:@"s03"],  
[UIImage imageNamed:@"s04"],  
[UIImage imageNamed:@"s05"],  
nil];

On low-res and high-res devices running iOS4, the images load as expected. On iOS3 the images cannot be found since the .png extension is seen as missing.

What's the right way to deal with this situation? Do I need to throw hacky conditionals throughout my code or is there a cleaner method?

Is something from Matt Gallagher's article a good approach?
http://cocoawithlove.com/2010/07/tips-tricks-for-conditional-ios3-ios32.html

A: 

See the "Loading Images into Your Application" section here.

Michael Kessler
A: 

You still get the auto '@2x' loading behavior in iOS4 even if you use the file extension, so [UIImage imageNamed:@"so1.png"] is fine (it will find "[email protected]" if you're running on a Retina Display with OS 4) plus it's backwards compatible with 3, where it will always find the low-res version of the file.

Art Gillespie