iOS图像命名约定 [英] iOS Image Naming Conventions

查看:130
本文介绍了iOS图像命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS开发中比较新的。



我目前正在使用可用于iPad Retina,iPad,iPhone 5和iPhone 4s / 4的cocos2d库建立应用程式。



我得到了所有的图像设置,我想知道命名约定。



知道一个指南,可以帮助我?



说我有一个background.png。



我的理解:




  • background.png - > iPhone(非视网膜/后备)

  • background-hd.png - > iPhone 4s / 4(retina)

  • background-ipad.png - > iPad(非视网膜)

  • 背景-ipadhd.png - > iPad(retina)



相同的命名约定将用于所有其他文件?例如:




  • arbitraryButton.png - > iPhone(非视网膜/后备)

  • arbitraryButton -hd.png - > iPhone 4s / 4(retina)

  • arbitraryButton-ipad.png - > iPad(非视网膜)

  • ipadhd.png - > iPad(retina)



我该如何命名iPhone 5文件?



我搜索了一些,似乎找不到任何有形的指南。



谢谢!

解决方案

操作系统有一个命名约定,你可以使用(并强制执行,意味着你只需要引用 @ fileName)。 文档位于此处。 / p>


  • fileName.png - > iPhone(非视网膜/后备)

  • fileName@2x.png - > iPhone 4s / 4(retina)

  • fileName〜ipad.png - > iPad(非视网膜)

  • fileName @ 2x〜ipad。 png - > iPad(retina)



注意:〜iphone也存在,可以使用/ ipad。使用〜ipad和〜iphone将保护苹果可能介绍的第三个成语。 咳嗽电视咳嗽



对于iPhone 5,操作系统不强制命名方案。




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



要在整个应用程序中轻松处理这个问题,您可以创建一个类别, iPhone 5的友好图像,以及一个正常大小的图像。可以创建一个简单的版本,如下所示。



UIImage + iPhone5Image.h

  #import< UIKit / UIKit.h> 

@interface UIImage(iPhone5Image)

+(UIImage *)iPhone5ImageNamed:(NSString *)imageName;

@end

UIImage + iPhone5Image.m

  #importUIImage + iPhone5Image.h

#define IsIPhone5()([UIDevice currentDevice] .userInterfaceIdiom == UIUserInterfaceIdiomPhone&& [UIScreen mainScreen] .bounds.size.height == 568)

@implementation UIImage(iPhone5Image)

+ *)iPhone5ImageNamed:(NSString *)imageName
{
if(IsIPhone5()){
NSString * newImageName = [NSString stringWithFormat:@%@ - 568h,imageName];
return [UIImage imageNamed:newImageName];
}
else {
return [UIImage imageNamed:imageName];
}
}

@end


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!

解决方案

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)
  • fileName@2x.png -> 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.

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

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

这篇关于iOS图像命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆