I'd like to design a background image for my app. The image should fill the iPhone screen. What image size that will work for 3G and 4G?
A) 320 x 480. B) 640 x 960.
I prefer to use B as it will have more quality, will 3G resize the image to fit?
Thanks for any he开发者_运维问答lp.
Simply author both sizes and save the hi-res with a @2x
suffix in the filename (like background.png
and background@2x.png
). iPhone 4 will use the hi-res image, older devices will stick to the ordinary one. See the docs for +[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.
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 is button, 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 to 2.0. Otherwise, it loads the unmodified filename and sets the scale property to 1.0. See iOS Application Programming Guide for more information on supporting images with different scale factors.
Also read the appropriate part of iOS Application Programming Guide.
Although it is trivial to resize the image to the proper size, you should prepare both 320×480 and 640×960 (and probably you need a 1024×768 for iPad too). In this way the system can choose the best image for that model.
Basically, you create a 320×480 background.png
for the older models, and a 640×960 background@2x.png
for retina display. Then load the image with
UIImage* backgroundImage = [UIImage imageNamed:@"background.png"];
in this way, the system will choose the best resolution automatically.
精彩评论