Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Image Naming Conventions

I'm relatively new in iOS development.

I'm currently building an app using the cocos2d library that will be available for the iPad Retina, iPad, iPhone 5, and iPhone 4s/4.

I'm getting all of my images setup, and I'm trying to figure out the naming conventions.

Does anyone know of a guide out there that could help me?

Say I have a background.png.

From what I understand:

  • background.png -> iPhone (non-retina/fallback)
  • background-hd.png -> iPhone 4s/4 (retina)
  • background-ipad.png -> iPad (non-retina)
  • background-ipadhd.png -> iPad (retina)

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

  • arbitraryButton.png -> iPhone (non-retina/fallback)
  • arbitraryButton-hd.png -> iPhone 4s/4 (retina)
  • arbitraryButton-ipad.png -> iPad (non-retina)
  • arbitraryButton-ipadhd.png -> iPad (retina)

What do I name the iPhone 5 files?

I've searched a bit and cant seem to find any tangible guides out there on this.

Thank you!

like image 747
Corey Avatar asked Feb 13 '13 17:02

Corey


People also ask

What is iPhone Photo naming convention?

The iPhone correctly names photos with the date and time they were taken. Everything I have used for years to deal with these photos relies on that file name. It's critical.

What does a Cisco IOS filename indicate?

Cisco creates a separate IOS for each series of routers. Because of this, each IOS works only on the router belonging to that series. The first term indicates the series of routers for which the IOS file is compiled. The word 'c1841' indicates that this IOS file is compiled for the 1841 series routers.

Which file naming convention is best?

File naming best practices: Avoid special characters or spaces in a file name. Use capitals and underscores instead of periods or spaces or slashes. Use date format ISO 8601: YYYYMMDD.


3 Answers

The OS has a naming convention that you can use (and enforces for you, meaning you only need to reference the file as @"fileName"). The documentation is available here.

  • fileName.png -> iPhone (non-retina/fallback)
  • [email protected] -> iPhone 4s/4 (retina)
  • fileName~ipad.png -> iPad (non-retina)
  • fileName@2x~ipad.png -> iPad (retina)

Note: ~iphone also exists, and can be used with/instead of using ~ipad. Using both ~ipad and ~iphone would safeguard against a third idiom Apple may introduce. cough TV cough

As for the iPhone 5, the OS does not enforce a naming scheme. But, it'd probably be wise to use the same scheme as that for the launch image.

To handle this easily throughout the app, you can create a category, and use it where you know you will have an iPhone 5 friendly image, as well as a regular sized image. A simple version can be made, like the one 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
like image 84
WDUK Avatar answered Oct 15 '22 12:10

WDUK


It looks like you are after the cocos2d naming conventions not the standard UIKit versions. They are different and if you are using cocos2d you are recommended to use the cocos2d suffixes and not the UIKit ones.

They are as follows:

  • Non retina iPhone (No suffix)
  • Retina iPhone -hd
  • Non retina iPad -ipad
  • Retina iPad -ipadhd
  • iPhone 5 -iphone5 and -iphone5hd

All files that you want loaded based on the device that are used with the cocos2d methods can be suffixed like this.

like image 30
Ben Trengrove Avatar answered Oct 15 '22 12:10

Ben Trengrove


Ok, Now cocos2d itself support 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 Cocos2d version is old then 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")];
like image 29
Guru Avatar answered Oct 15 '22 12:10

Guru