我试图在文本变大时截断标签,但它却从中心移动到左侧。
这是我的片段。
CCLabelTTF *playerLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Playerdadsadsd %d",i+1] fontName:@"Helvetica-Bold" fontSize:fontSize];
playerLabel.color = playerColor;
playerLabel.name = [NSString stringWithFormat:@"%d",1002+i];
playerLabel.position = ccp(playerSprite.position.x + playerSprite.contentSize.width + 10, yPos);
playerLabel.adjustsFontSizeToFit = YES;
[self addChild:playerLabel];
最佳答案
我不确定你想达到什么目的,但尝试将 dimensions
参数传递给 init 方法:
//The label won't go out of this rectangle
CGSize rect = CGSizeMake(viewSize.width * 0.1f, viewSize.height * 0.1f);
NSString *text = [NSString stringWithFormat:@"Playerdadsadsd %d",i+1];
CCLabelTTF *playerLabel = [CCLabelTTF labelWithString: text
fontName: @"Helvetica-Bold"
fontSize: fontSize
dimensions: rect]; // <-- Note this parameter
//.. the rest of your code..
关于ios - cocos2dV3.0中如何截断标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23994643/