我正在使用包装的UITextView
via UIViewRepresentable
。根据其内容,即(属性)字符串,该 textView 应该与所需的一样高。
struct TextView: UIViewRepresentable {
@Binding var text: String
func makeUIView(context: Context) -> UITextView {
let textView = UITextView()
textView.isScrollEnabled = false
textView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
return textView
}
func updateUIView(_ uiView: UITextView, context: Context) {
uiView.text = text
}
}
这工作正常:
struct TextView_Previews: PreviewProvider {
static var previews: some View {
TextView(text: .constant("some multiline\na\nb\nc\nd\nlorem ipsum"))
}
}
不工作
struct TextView_Previews: PreviewProvider {
static var previews: some View {
ScrollView { // <- when placed inside ScrollView the height is reduced to one line
TextView(text: .constant("some multiline\na\nb\nc\nd\nlorem ipsum"))
}
}
}
如何解决这个问题?