我想计算 NSAttributedString Multiline 的高度。它适用于单行(意味着它减去高度的领先)。但如果文本是多行的,它给出的结果与单行相同。
NSMutableParagraphStyle *titleParagraphStyle = [[NSMutableParagraphStyle alloc] init];
titleParagraphStyle.lineHeightMultiple = 0.9f;
titleParagraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
CGSize constrainedSize = CGSizeMake(TOUNameWidth, MAXFLOAT);
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
TOUNameFont, NSFontAttributeName,
titleParagraphStyle, NSParagraphStyleAttributeName,
nil];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString: name attributes:attributesDictionary];
CGRect rect = [string boundingRectWithSize:constrainedSize options:NSStringDrawingUsesFontLeading context:nil];
NSLog(@"rect is %f",rect.size.height);