ios - cocos2dV3.0中如何截断标签

标签 ios xcode cocos2d-iphone

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

这是我的片段。

 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];

enter image description here

最佳答案

我不确定你想达到什么目的,但尝试将 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/

相关文章:

ios - 从 AppDelegate 遍历到其他 Controller

ios - cordova/ios 媒体查询方向从不报告 "landscape"

objective-c - 当键盘出现在 iOS 中时,将 UIView 上移

ios - Guard Malloc 导致 wacko 应用程序行为

ios - 我应该从这里去哪里? (Cocos2D+UIKit)

xcode - 在Xcode中编译Box2D,构建目录问题

ios - Segue 方法及其目标

ios - NSAttributed 文本在 iOS 中带有一条线和一些角度

ios - 如何解释在 firebase 中没有完全符号化的崩溃报告?

objective-c - CCSpriteFrameCache 优化