Specifying high-resolution images in IOS

Source: Internet
Author: User
ArticleDirectory
    • IOS supports device-specific resources
Specifying high-resolution images in IOS

Any iPhone application built for iOS 4.0 and later shoshould include high-resolution versions of its image resources. when the application is run on a device that has a high-resolution screen, high-resolution images provide extra detail and look better because they do not need to be scaled to fit the space. you provide high-resolution images for each image resource in your application bundle, including icons and launch images.

To specify a high-resolution version of an image, create a version whose width and height (measured in pixels) are twice that of the original. (You can use the extra pixels in the image to provide additional detail .) when saving the image, use the same base name but include the string @ 2x Between the base filename and the filename extension. For example, if you have an image named Myimage.png , The name of the high-resolution version wocould be MyImage@2x.png . Put the high-resolution and original versions of your image in the same location in your application bundle.

the bundle-and image-loading routines automatically look for image files with the @ 2x string when the underlying device has a high-resolution screen. if you combine the @ 2x string with other modifiers, the @ 2x string shocould come before any device modifiers but after all other modifiers, such as launch orientation or URL scheme modifiers. thus, a universal application might have the following image resource files for a single image:

  • Myimage.png-Default version of the image resource, which is also used for iPad.

  • Myimage ~ Iphone.png-Version of the image for iPhone and iPod Touch.

  • Myimage @ 2X ~ Iphone.png-High-Resolution version of an image for iPhone and iPod Touch devices with retina displays.

When you want to load an image, do not include@ 2xOr any device modifiers when specifying the image name in your code. For example, If your application bundle has Ded the image files from the preceding list , You wocould ask for an image namedMyimage.png . The system automatically determines which version of the image is most appropriate and loads it. similarly, when using or drawing that image, you do not have to know whether it is the original resolution or high-resolution version. the image-drawing routines automatically adjust Based on the image that was loaded. however, if you still want to know whether an image is the original or high-resolution version, you can check its scale factor. if the image is the high-resolution version, its scale factor is set to a value other 1.0 .

For more information about how to support high-resolution devices, see"Supporting high-resolution screens".

 

Resource programming guideios supports device-specific resources

In IOS 4.0 and later, it is possible to mark individual resource files as usable only on a specific type of device. this capability simplifies the code you have to write for universal applications. rather than creating separate code paths to load one version of a resource file for iPhone and a different version of the file for iPad, you can let the bundle-loading routines choose the correct file. all you have to do is name your resource files appropriately.

To associate a resource file with a participant device, you add a custom modifier string to its filename. The specified sion of this modifier string yields filenames with the following format:

<Basename><Device>.<Filename_extension>

The<Basename>String represents the original name of the resource file. It also represents the name you use when accessing the file from your code. Similarly,<Filename_extension>String is the standard filename extension used to identify the type of the file.<Device>String is a case-sensitive string that can be one of the following values:

    • ~ IPad-The resource shoshould be loaded on iPad devices only.

    • ~ IPhone-The resource shoshould be loaded on iPhone or iPod Touch devices only.

You can apply device modifiers to any type of resource file. For example, suppose you have an image namedMyimage.png. To specify different versions of the image for iPad and iPhone, you wowould create resource files with the namesMyimage ~ Ipad.pngAndMyimage ~ Iphone.pngAnd include them both in your bundle. to load the image, you wowould continue to refer to the resourceMyimage.pngIn your code and let the system choose the appropriate version, as shown here:

Uiimage * animage = [uiimage imagenamed: @ "myimage.png"];

on an iPhone or iPod Touch device, the system loads the myimage ~ Iphone.png resource file, while on iPad, it loads the myimage ~ Ipad.png resource file. If a device-specific version of a resource is not found, the system falls back to looking for a resource with the original filename, which in the preceding example wocould be an image named myimage.png .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.