What to name images for iPhone 5 screen size?

后端 未结 1 742
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-30 01:39

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 (

1条回答
  •  逝去的感伤
    2021-01-30 02:17

    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")]];
    

    0 讨论(0)
提交回复
热议问题