我在iOS开发方面比较新。
我目前正在使用可用于iPad Retina,iPad,iPhone 5和iPhone 4s / 4的cocos2d库构建应用程序。
我正在设置所有图片,并且我正在尝试找出命名约定。
有没有人知道有哪些指南可以帮助我?
说我有一个background.png。
据我所知:
相同的命名约定将用于所有其他文件?例如:
我如何命名iPhone 5文件?
我搜索了一下,似乎找不到任何有形的指南。
谢谢!
答案 0 :(得分:10)
操作系统有一个您可以使用的命名约定(并强制执行,这意味着您只需要将文件引用为@"fileName"
)。文档is available here。
注意:~iphone也存在,可以和/而不是使用~ipad一起使用。同时使用~ipad和~iphone可以防止Apple可能引入的第三个习语。 咳嗽电视咳嗽
对于iPhone 5,操作系统不强制执行命名方案。但是,使用与发射图像相同的方案可能是明智的。
要在整个应用程序中轻松处理此问题,您可以创建一个类别,并在您知道将拥有iPhone 5友好图像以及常规尺寸图像的地方使用它。可以制作一个简单版本,如下所示。
<强>的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
答案 1 :(得分:3)
看起来你是在遵循cocos2d命名约定而不是标准的UIKit版本。它们是不同的,如果您使用cocos2d,建议您使用cocos2d后缀而不是UIKit后缀。
他们如下:
-hd
-ipad
-ipadhd
-iphone5
和-iphone5hd
您希望根据与cocos2d方法一起使用的设备加载的所有文件都可以加上这样的后缀。
答案 2 :(得分:2)
好的,现在cocos2d本身支持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
如果您的Cocos2d版本已旧,请使用:
static inline NSString *i5res(NSString * data)
{
if(IS_IPHONE5)
{
return [data stringByReplacingOccurrencesOfString:@"." withString:@"-whd."];
}
return data;
}
//usage
CCSprite *bg = [CCSprite spriteWithFile:i5res(@"bg.png")];
答案 3 :(得分:0)
要让编译器自动选择正确的图像,您需要命名标准(非视网膜)images image.png和视网膜图像image@2x.png。然后在您的代码中,请参考标准的代码。编译器将完成剩下的工作。因此,如果您要设置图像,它应该如下所示:
UIImage *anImage = [UIImage imageNamed:@"image.png"];
iPhone 5没有特定的命名约定,因为该应用程序不会自动为iPhone 5选择不同的图像大小,您必须在代码中执行以下操作:
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];
}