버튼을 모방 한 클래스가 있습니다. 여기에는 중앙에 (수평으로) 정렬하려고하는 하나의 레이블이 들어 있습니다. 내가 무엇을 시도하든, 레이블은 왼쪽면에 머물러있어 이것이 내가 생각하는 것보다 더 복잡하다고 생각하게 만든다. 여기에 유일한 초기화/설정 코드는 다음과 같습니다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
그 시점에서 'self.contentSize'는 무엇입니까? –