1

For instance I have image great_image.png and great_image@2x.png for retina display. If I want to create UIImage in code I just write:

UIImage *image = [UIImage imageNamed:@"great_image"];

But if I create UIImageView in xib and I want to set image in xib, I need to write image name. What should I write: "great_image.png" or "great_image@2x.png" or "great_image" ? (because if I write "great_image", I will not see image in xib).

Update: the second part of question:

What if I only have great_image@2x.png and don't have great_image.png, should I write great_image.png in xib anyway?

Paul T.
  • 4,938
  • 7
  • 45
  • 93

3 Answers3

1
  1. You need to set great_image.png in xib.Because it will take @2x image if it is in retina dispaly.
  2. if you don't have great_image.png image in your project in that case it will not display in non-retina device
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
  • pls take a look at the update: What if I only have great_image@2x.png and don't have great_image.png, should I write great_image.png in xib anyway? – Paul T. Aug 29 '13 at 05:53
  • about "if you don't have great_image.png image in your project in that case it will not display in non-retina device". So if I don't have great_image.png and I need to support non-retina devices I need to write great_image@2x.png in xib ? (because as I understood in this case the image will appear on non-retina device but with poorer quality). correct? – Paul T. Aug 29 '13 at 06:07
  • No, If you don't have great_image.png in your project in that case you can't load @2x image in non-retina display.@2x image will be available only in retina display. – Dharmbir Singh Aug 29 '13 at 06:13
  • I tried, and I can see image on non-retina device, but I don't have great_image.png file and have great_image.png in xib – Paul T. Aug 29 '13 at 06:30
  • i seems you run your either retina device or you need to clear your xcode n reset your simulator. Because i'm preety sure great_image.png won't work in non-retina display. – Dharmbir Singh Aug 29 '13 at 06:33
1

if you have great_image.png and great_image@2x.png in your project then when you use

UIImage *image = [UIImage imageNamed:@"great_image"];

It will automatically load great_image.png if your screen scale is 1.0 (iPhone3G/3GS) or great_image.png if your screen scale is 2.0 (retina, iPhone 4).

no need to specify great_image@2x.png

if you have only @2x image The high resolution @2x images are not automatically down-sampled on non-retina devices.

Non-retina devices will however down-size and display the high resolution @2x images, but without down-samling them, so it will result in to poor quality..

BhavikKama
  • 8,566
  • 12
  • 94
  • 164
0

You can set the image property of imageview from xib. you just have to give the name of that image.if image is not displaying in image view then check your bundle resources that whether that image is added into in or not. Secondly you dont have to specify @2x with image name because compiler decides at runtime by considering the device(non ratina or ratina).

Usama
  • 548
  • 3
  • 12