Вы можете использовать следующий код, чтобы отключить прокрутку textview:
textView.isScrollEnabled = false
И добавить свой textView внутри UIScrollView
.Это даст вам результат, который вы ожидали.
Или Вы можете программно сделать следующее:
var textView = UITextView()
var scrollView = UIScrollView()
func makeTextView() {
scrollView.backgroundColor = .green
textView.backgroundColor = .red
textView.text = "Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda."
textView.isScrollEnabled = false
scrollView.frame = CGRect(x: 0, y: 0, width:self.view.frame.size.width, height:50)
textView.frame = CGRect(x: 0, y: 0, width:self.view.frame.size.width, height:50)
view.addSubview(scrollView)
scrollView.addSubview(textView)
scrollView.translatesAutoresizingMaskIntoConstraints = false
textView.translatesAutoresizingMaskIntoConstraints = false
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
scrollView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor, constant: 0).isActive = true
scrollView.heightAnchor.constraint(equalToConstant: 50).isActive = true
textView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: 0).isActive = true
textView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor, constant: 0).isActive = true
textView.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: 0).isActive = true
textView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: 0).isActive = true
}