8

How to set corresponding MYimage.png for MyimageView in Xcode 6 with ios 8.x compatiblity.

MyimageView setImage:[UIImage imageNamed:@"MYimage.png"];

In Resources, I am having the following images with resolutions:

MYimage.png--320*480

MYimage@2x.png--640*960

MYimage-568h@2x.png--640*1136

MYimage-375h@2x.png--750*1334

MYimage-736h@3x.png--1242*2208

For iPhone 4s,it shows: MYimage@2x.png [Right]

For iPhone 5s,it shows: MYimage@2x.png [wrong]

For iPhone 6,it shows: MYimage@2x.png [wrong]

For iPhone 6+,it shows: MYimage@2x.png [wrong]

But after renaming the images as mentioned below:

MYimage.png--320*480

MYimage@2x.png--640*960

MYimage-568h@2x.png--640*1136

MYimage-375h@2x.png--750*1334

MYimage@3x.png--1242*2208

For iPhone 4s,it shows: MYimage@2x.png [Right]

For iPhone 5s,it shows: MYimage@2x.png [wrong]

For iPhone 6,it shows: MYimage@2x.png [wrong]

For iPhone 6+,it shows: MYimage@3x.png [Right]

So., What's the stated format to implement?

Note: Also googled following Links and so on..

Community
  • 1
  • 1
Vikas Rajpurohit
  • 123
  • 1
  • 1
  • 6

2 Answers2

9

iOS only supports the size notations for launch images, for example this page describes the usage for 3.5", 4", and iPads in the format Default-568h@2x.png, etc.

What you're actually only able to support is @2x and @3x (see here) which explains why on each of the devices you're seeing it pick up the @2x and @3x pngs only.

Lastly, the MYimage@Xx.png--w*h isn't a valid size denotation either; those files won't be read by the system automatically when you reference an image named MYimage.png; at most you could do MYimage@2x.png and MYimage@3x.png.

Answering your question below:

iPhone 6 and iPhone 5 both render at the same pixel density. UI elements should be positioned correctly in the UI at the same point size on both devices.

For example:

iPhone 5       iPhone 6
|      |      |        |
|      |      |        |
|      |      |        |
|[bttn]|      |        |
|______|      | [bttn] |
              |________|

If you're displaying an photo in a UIImageView though, you can just create the largest size and let it either scale down to the iPhone 5 (using UIViewContentModeScaleAspectFill) or leave it as-is (using UIViewContentModeCenter).

In the end, you really don't want to have to manage specific dimensions for every single device out there - already if you're including 2 high-res assets for each element, that's a lot of storage space. Adding one for every device is unnecessary, and Apple never intended for that to be the case.

brandonscript
  • 68,675
  • 32
  • 163
  • 220
  • Then how to use the different sized image for iphone 5 and iphone 6.Loading unique name(nativescale) is the only solution? – Vikas Rajpurohit Oct 02 '14 at 12:52
  • "iOS only supports the size notations for launch images" -- this is not true. If you call `[UIImage imageNamed: @"foo"]`, iOS will load foo.png, foo@2x.png, foo~ipad.png or foo@2x~ipad.png, based on the platform. As you say, Launch images also supports `Default-536h@2x.png` (4"/iPhone5) – Olie Feb 11 '15 at 22:35
  • @Olie yes, it's true, iOS will not load `[UIImage imageNamed: @"foo"]` and get you the image named `foo-356h@2x.png`. – brandonscript Feb 11 '15 at 23:42
9

You don't need to specify what screen size the image is for, but only what density it is.

There are 3 density groups:

  • 1x: iPhone 3GS and previous; iPod Touch 3rd gen and previous; iPad 2 and previous; iPad Mini 1st gen;
  • 2x: iPhones 4, 4S, 5, 5S and 6; iPod Touch 4th and 5th gen; iPad 3 and newer; iPad Mini 2nd gen;
  • 3x: iPhone 6 Plus;

To each group, you should add an image named with the pattern "file_name@density.ext", where the density can be omitted for 1x.

Examples:

  • logo.png
  • logo@2x.png
  • logo@3x.png

For a better use and organization of your image resources, you should consider using Asset Catalogs. They will also help you understand what image sizes you will need depending on what devices you will support, and you will not need to care about each individual file name.

Rob Bajorek
  • 6,382
  • 7
  • 44
  • 51
Guilherme
  • 7,839
  • 9
  • 56
  • 99
  • iPhone SE, iPhone 6S, 7 should be added to 2x group, while iPhone 6S Plus and 7 Plus, along with iPad Pro should be added to 3x group. – Raptor Sep 13 '16 at 09:44