概要: テキスト ビューのスクロールを無効にし、高さを制限しないでください。
これをプログラムで行うには、次のコードを に追加しますviewDidLoad
。
let textView = UITextView(frame: .zero, textContainer: nil)
textView.backgroundColor = .yellow // visual debugging
textView.isScrollEnabled = false // causes expanding height
view.addSubview(textView)
// Auto Layout
textView.translatesAutoresizingMaskIntoConstraints = false
let safeArea = view.safeAreaLayoutGuide
NSLayoutConstraint.activate([
textView.topAnchor.constraint(equalTo: safeArea.topAnchor),
textView.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor),
textView.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor)
])
Interface Builder でこれを行うには、テキスト ビューを選択し、属性インスペクターで Scrolling Enabled のチェックを外し、制約を手動で追加します。
注: テキスト ビューの上/下に他のビューがある場合は、 を使用しUIStackView
てそれらをすべて配置することを検討してください。