gpt4 book ai didi

iphone - 无法设置 CCLabelTTF anchor

转载 作者:行者123 更新时间:2023-11-29 04:49:43 24 4
gpt4 key购买 nike

我将 CCLabelTTF 与 NSLocalizedString 一起使用,但我无法设置 anchor 。 (我希望所有按钮都左对齐,因此应该是 ccp(0, 0.5f),但在任何本地化中,结果始终居中。以下方法位于 Helper.m 中,我调用 CCLabelTTF* startLabel = [Helper createItemLabelWithStringUpperCase: @"PLAY!!!"]

+(CCLabelTTF*) createLocalizedLabelWithStringUpperCase: (NSString*) str color: (ccColor3B) c fontSize: (int) s {
NSString* font;
if ([Helper useCutomFontFile]) {
font = @"font.ttf";
}
else {
font = @"Arial";
}
CCLabelTTF* label = [CCLabelTTF labelWithString:NSLocalizedString(str, nil) fontName:font fontSize:s];
CCLOG(@"%@\n", str);
CCLOG(@"%@\n", NSLocalizedString(str, nil));

label.color = c;
return label;
}

+(CCLabelTTF*) createLocalizedLabelWithStringUpperCase: (NSString*) str color: (ccColor3B) c {
return [Helper createLocalizedLabelWithStringUpperCase:str color:c fontSize:32];
}

+(CCLabelTTF*) createUnlocalizedLabelWithString:(NSString *)str color:(ccColor3B)c fontSize: (int) s {
CCLabelTTF* label = [CCLabelTTF labelWithString: str fontName:@"font.ttf" fontSize:s];
label.color = c;
return label;
}
+(CCLabelTTF*) createUnlocalizedLabelWithString: (NSString*) str color: (ccColor3B) c {
return [Helper createUnlocalizedLabelWithString:str color:c fontSize:32];
}
+(CCLabelTTF*) createItemLabelWithStringUpperCase: (NSString*) str {
CCLabelTTF* label = [Helper createLocalizedLabelWithStringUpperCase:str color:ccBLACK];
label.anchorPoint = ccp(0, 0.5f);
return label;
}

顺便说一句,我在哪里可以找到一些常见的本地化词汇,例如“播放”、“继续”、“暂停”等?我认为谷歌翻译不够准确

最佳答案

在这里查看 CCLabelTTF 类引用:

http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_c_c_label_t_t_f.html

然后试试这个方法:

labelWithString:dimensions:alignment:fontName:fontSize:

或者这个:

initWithString:dimensions:alignment:fontName:fontSize:

创建具有对齐方式的 CCStringTTF。

对齐可以是以下之一:

CCTextAlignmentLeft     
CCTextAlignmentCenter
CCTextAlignmentRight

关于iphone - 无法设置 CCLabelTTF anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9053109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com