I would like to know when text exceeds the bounds of a UITextView and requires the user to scroll. Knowing how many lines a certain font will occupy is useless - how do I know how many lines a certain amount of text will take up?

In the image above, I would add a fade effect so that I can cut off the text view gracefully. However, it does not look correct to display the fade if there is not enought text to scroll.
Get contentSize after setting the text. It's a CGSize and the height will be the height required for the UITextView to display the text without scrolling.
myTextView.text = someText;
CGSize textSize = myTextView.contentSize;
float verticalSpaceNeededByText = textSize.height;
Updated for Swift 5.x
func textExceedBoundsOf(_ textView: UITextView) -> Bool {
textView.contentSize.height > self.textView.bounds.height
}
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