问题描述
||
我正在使用下面的代码来计算字符串标签的大小。
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字符串中的字符来更改行。当我在标签上显示此字符串并将其numberOfLines属性设置为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);
这给了我2英镑,但请确保将标签中的行数设置为3英镑。