Paul T.
Paul T.

Reputation: 5038

UIImage name in xibs issue: should I use @2x

For instance I have image great_image.png and [email protected] 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 "[email protected]" 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 [email protected] and don't have great_image.png, should I write great_image.png in xib anyway?

Upvotes: 1

Views: 200

Answers (3)

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

  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

Upvotes: 1

BhavikKama
BhavikKama

Reputation: 8800

if you have great_image.png and [email protected] 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 [email protected]

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..

Upvotes: 1

Usama
Usama

Reputation: 548

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).

Upvotes: 0

Related Questions