Not including retina-free images in the iPhone project

I have an iPhone Xcode project that currently only contains images for displaying the retina (twice the size of the regular one and with the suffix @ 2x.png). When I launch the application on the iPhone Simulator (no retina), the images are still displayed. Does this mean that I donโ€™t have to worry about including two sets of images: the retina and the non-retina?

It all seems a little strange. I would suggest that no images will appear on a device without a retina if files without @ 2x are not included in it.

Note. I have not tested my application on a non-retina device. Just a simulator.

+4
source share
3 answers

Even if it works, this is not a good practice, and if you have a heavy media application, it can affect the performance and battery life, as well as the printing of memory and ...

By the way, you simply do not have 1x graphics available to you, or your applications (download size) or ...

+1
source

I'm pretty sure that iOS will just use @ 2x and scale it if you don't have graphics without a retina. Although this is not optimal, since you let iOS do run-time scaling, which will be slower than turning on a graphic image without a retina, and iOS, it may not work as well as scaling as your graphics editor optionally.

+2
source

If you assign images in Interface Builder and set the image property on UIImageView to image@2x.png , for example, iOS will not know that this is a 2x high resolution image. In fact, on the retina screen, iOS will look for an image named image@2x @2x.png . Since he will not find it, he will set the scale factor of the image to 1.0.

The contentMode property (only โ€œmodeโ€ in Xcode) decides whether any image scaling will comply with UIImageView restrictions. You might want to set the Aspect Fit mode to get a high resolution image for scaling as needed for retina and non-retina displays. In general, the image will be displayed as shown in Interface Builder.

If you use UIImage imageNamed or a similar function to upload an image and simply specify image (where "image.png" does not exist but " image@2x.png " does), then iOS will actually find the image on the screen without a retina, although the scale factor will be 1.0. As before, you need to scale it to fit your idea. The image will work fine on the retina device, and the zoom factor will be set to 2.0, since iOS first looks for the โ€œ2xโ€ image, and it doesn't matter if another file exists or not.

This is from the Apple documentation on imageNamed :

On a device running iOS 4 or later, the behavior is identical if the device screen is 1.0. If the screen has a scale of 2.0, this method first searches for an image file with the same file name with the suffix @ 2x added to it. For example, if the file name, it first searches for the @ 2x button. If it finds 2x, it loads this image and sets the scale property of the returned UIImage to 2.0. Otherwise, it loads the unmodified file name and sets the scale property 1.0. See the iOS Application Programming Guide for more information on supporting images with different scale factors.

If at all possible, you really should include images of the retina and not the retina. Using images with a higher resolution than necessary will adversely affect memory and performance.

+1
source

Source: https://habr.com/ru/post/1389818/


All Articles