You need to:
- constrain the Bottom of the text view
- give it a minimum height
- disable scrolling of the text view
Quick example:
class QuickExampleViewController: UIViewController {
let textView = UITextView()
override func viewDidLoad() {
super.viewDidLoad()
// so we can see it
textView.backgroundColor = .cyan
// disable scrolling
textView.isScrollEnabled = false
// set the font
let font: UIFont = .systemFont(ofSize: 20.0, weight: .light)
textView.font = font
// we want the height to be at least one-line high
// even if it has no text yet
let minHeight: CGFloat = font.lineHeight
textView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(textView)
let g = view.safeAreaLayoutGuide
NSLayoutConstraint.activate([
// Leading / Trailing -- will likely be based on other UI elements
textView.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 60.0),
textView.trailingAnchor.constraint(equalTo: g.trailingAnchor, constant: -60.0),
// Bottom constraint, so it will "grow up"
textView.bottomAnchor.constraint(equalTo: g.topAnchor, constant: 300.0),
// at least minHeight tall
textView.heightAnchor.constraint(greaterThanOrEqualToConstant: minHeight),
])
}
}