获取字符串的内容大小

时间:2015-03-05 12:30:36

标签: c++ string cocos2d-x

是否可以在content size中获得string c++。我不是在说这里的长度。我希望将一个接一个的字符串放在一行中,比如label,但不想获得标签的内容大小。我需要在屏幕上显示一个字符串。

1 个答案:

答案 0 :(得分:0)

使用C ++字符串无法提出要求。

可能你可以使用NSString和sizeWithFont:

这样的东西
NSString *str= @"Hello, World!"
UIFont * font = [UIFont fontWithName:@"YourFontName" size:11];
CGSize supposedSize = [str sizeWithFont:font constrainedToSize:CGSizeMake(100, 100)];    
CCLabelTTF *label = [CCLabelTTF labelWithString:str dimensions:supposedSize fontName:@"YourFontName" fontSize:11];

找出cocos2d中文本的高度和宽度。