Supporting both high-res and low-res images
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开发者_JAVA技巧"],
[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.htmlYou 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 "so1@2x.png" 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.
See the "Loading Images into Your Application" section here.
精彩评论