In fact, you do not need to play with textContainer and layoutManager . This works for me.
UIBezierPath *exclusionPath = [UIBezierPath bezierPathWithRect:imageViewFrame]; UITextView *tempTextView = [[UITextView alloc] init]; [tempTextView setFont:font]; tempTextView.textContainer.exclusionPaths = @[exclusionPath]; [tempTextView.textStorage replaceCharactersInRange:NSMakeRange(0, [tempTextView.text length]) withString:text]; CGRect textViewFrame = [tempTextView frame]; textViewFrame.size.height = [tempTextView sizeThatFits:CGSizeMake(290, FLT_MAX)].height; return textViewFrame.size.height;
Dinesh raja
source share