根据设置的字符串字体大小,计算字符串的高度,目前计算出来的高度是一行的高度,但是显示的却是2行的高度,这是什么原因?
textview = [[UITextView alloc] init];
[textview setFrame:CGRectMake(5, 20, 310, 450)];
textview.font = [UIFont systemFontOfSize:20];
textview.editable = NO;
textview.scrollEnabled = YES;
NSString *text = @" 在现代酒已经融入了人们日常";
CGSize labelSize1;
labelSize1 = [text sizeWithFont:[UIFont systemFontOfSize:20]
constrainedToSize:CGSizeMake(310, CGFLOAT_MAX)
lineBreakMode:NSLineBreakByCharWrapping];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
paragraphStyle.lineSpacing = 5; //行间距
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, text.length)];
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, text.length)];
textview.attributedText = attributedString;
[self.view addSubview:textview];