IOS image naming conventions

I am relatively new to iOS development.

I am currently creating an application using the cocos2d library, which will be available for iPad Retina, iPad, iPhone 5 and iPhone 4s / 4.

I get all the settings for my images and I'm trying to understand the naming conventions.

Does anyone know of a guide that can help me?

Say I have background.png.

From what I understand:

  • background.png → iPhone (no retina / backup)
  • background-hd.png → iPhone 4s / 4 (retina)
  • background-ipad.png → iPad (no retina)
  • background-ipadhd.png → iPad (retina)

And will the same naming convention be used for all other files? For example:

  • Button.png -> iPhone (no retina / standby)
  • anyButton-hd.png → iPhone 4s / 4 (retina)
  • anyButton-ipad.png → iPad (no retina)
  • anyButton-ipadhd.png → iPad (retina)

What can I call iPhone 5 files?

I searched a bit and did not seem to find any tangible manuals there.

Thanks!

+7
source share
4 answers

The OS has a naming convention that you can use (and is mandatory for you, which means you only need to refer to the file as @"fileName" ). Documentation is available here .

  • fileName.png → iPhone (no retina / backup)
  • fileName@2x.png → iPhone 4s / 4 (retina)
  • fileName ~ ipad.png → iPad (no retina)
  • fileName@2x ~ ipad.png → iPad (retina)

Note: ~ iphone also exists and can be used with / instead of using ~ ipad. Using both the ipad and iphone will provide protection from the third idiom that Apple may present. cough tv cough

As with the iPhone 5, the OS does not use a naming scheme. But it would probably be wise to use the same scheme as for the startup image.

  • fileName-568h@2x.png → iPhone 5

To easily deal with this throughout the application, you can create a category and use it where you know that you will have an image with support for iPhone 5, as well as an image of a normal size. A simple version can be done as shown below.

UIImage + iPhone5Image.h

 #import <UIKit/UIKit.h> @interface UIImage (iPhone5Image) + (UIImage*)iPhone5ImageNamed:(NSString*)imageName; @end 

UIImage + iPhone5Image.m

 #import "UIImage+iPhone5Image.h" #define IsIPhone5() ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568) @implementation UIImage (iPhone5Image) + (UIImage*)iPhone5ImageNamed:(NSString*)imageName { if (IsIPhone5()) { NSString* newImageName = [NSString stringWithFormat:@"%@-568h", imageName]; return [UIImage imageNamed:newImageName]; } else { return [UIImage imageNamed:imageName]; } } @end 
+9
source

It looks like you are following the cocos2d naming conventions, not the standard versions of UIKit. They are different, and if you use cocos2d, you are advised to use the suffixes cocos2d, not UIKit.

They look like this:

  • Retina-free iPhone (no suffix)
  • Retina iPhone -hd
  • Not -ipad iPad- -ipad
  • Retina iPad - -ipadhd
  • iPhone 5 -iphone5 and -iphone5hd

All files that you want to download based on the device that are used with cocos2d methods can be compressed as follows.

+3
source

Ok, now cocos2d itself supports iphone5.

 -hd.png for iPhone HD -ipad.png for iPad -ipadhd.png for iPad HD -wide.png for iphone 5 -widehd.png for iPhone 5 HD 

If your version of Cocos2d is out of date, use:

 static inline NSString *i5res(NSString * data) { if(IS_IPHONE5) { return [data stringByReplacingOccurrencesOfString:@"." withString:@"-whd."]; } return data; } //usage CCSprite *bg = [CCSprite spriteWithFile:i5res(@"bg.png")]; 
+2
source

In order for the compiler to automatically select the correct image, you will want to name the standard (non-mesh) images image.png and retina images image@2x.png. Then in your code just refer to the standard one. The compiler will do the rest. Therefore, if you install an image, it should look like this:

 UIImage *anImage = [UIImage imageNamed:@"image.png"]; 

There is no special naming convention for iPhone 5, because the application will not automatically select a different image size for iPhone 5, you will have to do it in your code something like this:

 CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenHeight = screenRect.size.height; if([[UIScreen mainScreen]bounds].size.height == 568){ UIImage *signUp = [UIImage imageNamed:@"signup-bg-568h.jpg"]; [signUpImage setImage:signUp]; } else{ UIImage *signUp = [UIImage imageNamed:@"signup.jpg"]; [signUpImage setImage:signUp]; } 
0
source

All Articles