我试图在文本变大时截断标签,但它从中心移动到左侧扩展了。

这是我的片段。

 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..

08-05 07:46