本文介绍了Cocos2d:如何垂直对齐CCLabelTtf与不同的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用不同的字体大小垂直调整两个CCLabelTtf?感谢
How to aligh two CCLabelTtf vertically with different font size? Thanks
这是我创建标签的方式:
This is how I am creating labels:
for (int i = 0; i < 5; i++) {
CCLabelTTF *label = [CCLabelTTF labelWithString:@"11km 90m" fontName:@"Limelight.ttf" fontSize:20];
label.anchorPoint = ccp(0.5, 0.5);
label.position = ccp((size.width-225)/2 + 30, size.height - (size.height-260)/2 -i * 40 - 28);
[self addChild:label];
CCLabelTTF *label1 = [CCLabelTTF labelWithString:@"2013/11/22" fontName:@"Limelight.ttf" fontSize:15];
label1.anchorPoint = ccp(0.5, 0.5);
label1.position = ccp(160 + 25, size.height - (size.height-260)/2 -i * 40 - 28);
[self addChild:label1];
CCLabelTTF *label2 = [CCLabelTTF labelWithString:@"21 : 00" fontName:@"Limelight.ttf" fontSize:10];
label2.anchorPoint = ccp(0.5, 0.5);
label2.position = ccp(size.width - ((size.width-225)/2 + 30) + 20, size.height - (size.height-260)/2 -i * 40 - 28);
[self addChild:label2];
}
推荐答案
使用cocos2d 2.x, :
With cocos2d 2.x, use the following :
CCLabelTTF *label = [CCLabelTTF labelWithString:inText
fontName:_defaultMenuItemFont
fontSize:_defaultMenuItemFontSize
dimensions:inSize
hAlignment:inAlignment
];
label.verticalAlignment = kCCVerticalTextAlignmentCenter;
我注意到,使用各种2.1版本之一,你可能需要这样做后设置垂直以便其正常工作:
i noticed that with one of the various 2.1 builds, you may have to do this AFTER setting the vertical alignment in order for it to work properly:
[label setString:inText];
这篇关于Cocos2d:如何垂直对齐CCLabelTtf与不同的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!