我有一个模仿按钮的类。它包含一个标签,我试图集中对齐(水平)。无论我尝试什么,标签都留在左手边,这让我觉得这比看起来更复杂。这是唯一的初始化/设置代码:CCLabelTTF文本对齐
-(CCButtonLayer*)initWithText:(NSString*)text bgColor:(ccColor4B)color width:(GLfloat)width height:(GLfloat)height {
self = [super initWithColor:color width:width height:height];
self.lbl = [CCLabelTTF labelWithString:text fontName:@"Marker Felt" fontSize:22];
self.lbl.horizontalAlignment = kCCTextAlignmentCenter;
[self.lbl setHorizontalAlignment:kCCTextAlignmentCenter];
self.lbl.color = ccc3(0,0,0);
// self.lbl.contentSize = CGSizeMake(width, height); // no effect anyway
self.lbl.anchorPoint = CGPointZero;
self.lbl.position = CGPointZero;
[self addChild:self.lbl];
return self;
}
不幸的是没有效果。 – Echilon 2012-08-18 18:42:15
那个时候什么是'self.contentSize'? – 2012-08-18 18:50:41