As shown in above diagram ... the lineHeight
is the height of the orange box. How can I get the height of the blue box (i.e. lineHeight
+ line spacing height)? Thanks!
UPDATE: I found the the lineHeight
behaves differently depends on the characters in content. If the content is all in English, the lineHeight is corrent (21, for example, in the default UITextView). However, when the content is mixed with Chinese characters, the UIFont lineHeight
is still reported as 21 while the self.textView.contentSize.height
is increased differently:
English - adding 21 points for each line
Chinese - adding 24 points for each line
UPDATE (sizeWithFont:
)
CGSize constrainedRect = CGSizeMake(1000, 1000);
CGSize rectEnglish = [@"hello\nworld" sizeWithFont:self.textView.font constrainedToSize:constrainedRect lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"width: %.2f height: %.2f", rectEnglish.width, rectEnglish.height);
CGSize rectChinese = [@"你\n好嗎" sizeWithFont:self.textView.font constrainedToSize:constrainedRect lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"width: %.2f height: %.2f", rectChinese.width, rectChinese.height);
output:
width: 41.00 height: 42.00
width: 34.00 height: 42.00
You have to use
yourTextView.font.lineHeight
Try using the NSString
UIKit
additions. Some variation of -sizeWithFont:
should be what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With