iOS不使用-568h@2x.png

0xS*_*ina 9 iphone cocoa-touch objective-c ios

我有3张图片:

test.png
test@2x.png
test-568@2x.png
Run Code Online (Sandbox Code Playgroud)

在IBOutlet中,UIImageView设置为显示test.png.

在没有视网膜的iPhone 3.5in上,它显示test.png

在带视网膜的iPhone 3.5in上,显示test@2x.png

但是在带视网膜的iPhone 4in上,显示的是test@2x.png!

这是怎么回事?

谢谢!

rma*_*ddy 9

-568@2x后缀仅适用于为Default.png启动图像.UIImage imageNamed:(或其他UIImage方法)没有使用特殊后缀.如果您需要在4"屏幕上显示特殊图像,则需要添加代码以自行获取所需图像.


jcs*_*ica 7

以下适用于iPhone.对于iPad,您需要其他图像.

对于背景图像的三个版本,请使用以下名称:

  1. background-480h.png(320x480)
  2. background-480h@2x.png(640x960)
  3. background-568h@2x.png(640x1136)

(您不需要"-568h.png"图像,因为iPhone屏幕没有320x568.)

设置背景图像时,只需将屏幕高度附加到图像名称:

NSString* imageName = [NSString stringWithFormat: @"background-%ih", (int)[[UIScreen mainScreen] bounds].size.height];
[view setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: imageName]]];
Run Code Online (Sandbox Code Playgroud)

iOS自动添加"@ 2x"(如果适用).

您可以省略图像名称中高度之后的"h",但我认为模拟默认图像的iOS约定是很好的.