如何命名iPhone 5屏幕尺寸的图像?

问题描述:

4英寸视网膜显示图像的新命名规则是什么?如何命名iPhone 5屏幕尺寸的图像?

对于命名background.png图像您@ 2X添加到名称([email protected])告诉iOS系统使用一个与视网膜显示设备。

对于iPhone 5的屏幕尺寸,后缀是什么?

+0

见http://*.com/questions/12518879/extend-app-for-iphone-5-best-practice相关信息,这是唯一的似乎存在的“惯例”。否则,继续像以前一样使用@ 2x。 –

你可以用我#define s到帮助您与这些图片:

#define isPhone568 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568) 
#define iPhone568ImageNamed(image) (isPhone568 ? [NSString stringWithFormat:@"%@-568h.%@", [image stringByDeletingPathExtension], [image pathExtension]] : image) 
#define iPhone568Image(image) ([UIImage imageNamed:iPhone568ImageNamed(image)]) 

只要给您的图片[email protected]符号,并使用iPhone568ImageNamed以获取标准名称或iPhone 5的名称/新的iPod。从评论

用例:

self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:iPhone568ImageNamed(@"mainscreen.png")]]; 
+0

问:如果名称以“foo.png”的形式传入,它不会最终转换为“foo.png-568h”吗? –

+7

啊,这个怎么样? #define iPhone568ImageNamed(image)(isPhone568?[NSString stringWithFormat:@“%@ - 568h。%@”,[image stringByDeletingPathExtension],[image pathExtension]]:image) –

+0

这是个好主意,我会将它添加到答案中。 –