您的位置:首页 > 其它

CCLabelTTF with fixed width and dynamic height solution

2014-08-22 11:51 671 查看
CGSize size =[[CCDirectorsharedDirector]winSize];
NSString *str = [NSString stringWithString:@" did a bit of research and was able tofind out the size of an nsstring within a constraint then applythat to the label which has worked so far for me. Hopefully thiscan help someone stuck with the same problem I was having. I dohowever get a bunch of context errors which I have no idea how tofix, but they don't seem to stop anything fromworking."];
UIFont *font = [UIFont fontWithName:@"Marker Felt" size:16];
CGSize compSize = [str sizeWithFont:font constrainedToSize:CGSizeMake(size.width *0.8,2000)lineBreakMode:UILineBreakModeWordWrap];
CCLabelTTF *label = [CCLabelTTF labelWithString:str dimensions:compSize alignment:UITextAlignmentLeft fontName:@"MarkerFelt" fontSize:16];
NSLog(@"width:%f, height:%f",compSize.width,compSize.height);
label.position=  ccp(size.width /2 , size.height/2 );
[self addChild: label];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐