iphone:sizeWithFont方法不识别'\n';从字符串
我使用下面的代码来计算字符串标签的大小iphone:sizeWithFont方法不识别'\n';从字符串,iphone,dynamic,size,uilabel,Iphone,Dynamic,Size,Uilabel,我使用下面的代码来计算字符串标签的大小 NSString * str = @"It's \n that \n don't \n"; CGSize size = [str sizeWithFont:[UIFont fontWithName:@"Verdana" size:12.5] forWidth:300 lineBreakMode:UILineBreakModeWordWrap]; NSLog(@"Height : %f Width : %f ",si
NSString * str = @"It's \n that \n don't \n";
CGSize size = [str sizeWithFont:[UIFont fontWithName:@"Verdana" size:12.5] forWidth:300
lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"Height : %f Width : %f ",size.height,size.width);
但ID不考虑字符串中的n个字符来更改行。当在标签上显示该字符串并将其编号为4或5时,标签会考虑\n并转到下一行。如何计算标签的高度(考虑到字符串的\n)。请帮帮我
谢谢你 试试这个:NSString * str = @"It's \n that \n don't \n";
CGSize size = [str sizeWithFont:[UIFont fontWithName:@"Verdana" size:12.5] constrainedToSize:CGSizeMake(300.0f, 999999.0f)];
NSLog(@"Height : %f Width : %f ",size.height,size.width);
这给了我高度:48.000000宽度:40.000000
,但一定要将标签中的行号设置为0