I have a UITextView and I need to calculate it's content size before the new character appears on editing. I've tried the following:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
CGSize size = [[textView.text stringByReplacingCharactersInRange:range
withString:text]
sizeWithFont:textView.font
constrainedToSize:CGSizeMake(textView.contentSize.width, 200)
lineBreakMode:UILineBreakModeWordWrap];
return YES;
}
I set a breakpoint at the line with return
. The content insets are 0 each.
The problem is that the size
has a height of 60, but the textView.contentSize.height
is 76 (and I enter a character, not delete one so it should be 76 if no new line is required or greater than 76 if I`m at the end of line). Anyone knows why is this happening?
Thanks in advance!