What to name images for iPhone 5 screen size?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 08:03:24

问题


What is the new naming convention for images for the 4-inch retina display?

For an image named background.png you add @2x to the name (background@2x.png) to tell iOS to use that one for devices with the retina display.

What would the suffix be for iPhone 5's screen size?


回答1:


You can use my #defines to help you with these images:

#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)])

Just give your images the -568h@2x.png notation, and use iPhone568ImageNamed to get a name for standard name or iPhone 5/new iPod.

Usage example from the comments:

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


来源:https://stackoverflow.com/questions/12519110/what-to-name-images-for-iphone-5-screen-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!