CCLabelTTF with fixed width and dynamic height solution

来源:互联网 发布:algorithm基础算法 编辑:程序博客网 时间:2024/05/23 11:25

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


0 0