0

After reading Apple's own HIG (specifically the 'Creating images for retina..' section) and looking at similar answers and suggested blogs - I can't seem to get a good solid fix on how properly design images for retina.

To best explain, let me set up a scenario:

  • I have a UIButton that is 44 x 44 points that I laid out in IB.

  • I go to photoshop, create an image that is 44 x 44 pixels. I save that as image@2x.png

  • I save another, without the @2x.png appended on the file name.

  • In the code, I do something like ... [UIImage imageNamed:@"image"]

From what I have read, it seems that DPI doesn't matter. I do also understand that retina images are, of course, double in scale to the original image. So for the scenario above, was the image@2x.png supposed to be 88 x 88 pixels instead of 44 x 44 pixels? In the [UIImage imageNamed:@"image"], do I need to specify the @2x in the image's name, or does xcode take care of that?

Going with the scenario I described above, can someone either correct me or confirm that this is the correct pixel dimensions the image?

4

2 回答 2

2

你描述的场景是错误的。

这里是右边:

  1. 假设您希望在 IB 中放置一个 44pt x 44pt 按钮;
  2. 转到 Photoshop 创建一个 88px x 88px 的图像,以 @2x 命名;
  3. 创建另一个 44px x 44px 的图像,不添加 @2x;
  4. 在您的 IB 或代码中,设置图像使用普通名称,图像名称中不带 @2x。系统将正常显示正常图像和@2x 图像。
于 2013-07-28T15:04:10.193 回答
1

要创建 IB 大小为 44x44 的按钮,您需要两个图像:

  1. Image.png 大小为 44x44
  2. Image@2x.png 大小为 88x88

当您使用基本名称时,iOS 会自动选择正确的文件

要在代码中加载该图像,您只需使用以下行:

[UIImage imageNamed:@"Image"]

再一次,iOS 将获得正确的图像

于 2013-07-28T14:57:01.407 回答