I have a TextView that has a constraint of min height of 33. The scroll is disabled from the storyboard. The TextView should increase in height based on the content until it
It seems your code requires two changes, and it will work fine.
Change code as below:
import UIKit
class ViewController: UIViewController, UITextViewDelegate
{
@IBOutlet weak var messageTextView: UITextView!
let messageTextViewMaxHeight: CGFloat = 100
override func viewDidLoad()
{
super.viewDidLoad()
messageTextView.delegate = self
}
func textViewDidChange(textView: UITextView)
{
if textView.contentSize.height >= self.messageTextViewMaxHeight
{
textView.scrollEnabled = true
}
else
{
textView.frame.size.height = textView.contentSize.height
textView.scrollEnabled = false // textView.isScrollEnabled = false for swift 4.0
}
}
}