How to use an NSAttributedString with a ScrollView in SwiftUI?

后端 未结 2 749
有刺的猬
有刺的猬 2021-01-13 21:07

I\'ve been able to render NSAttributedStrings via UIViewRepresentable which works great until I wrap the view in a ScrollView.

<
2条回答
  •  甜味超标
    2021-01-13 21:34

    If you want to use Asperi's TextWithAttributedString as a child view, replace

    height = textView.sizeThatFits(UIScreen.main.bounds.size).height
    

    by

    DispatchQueue.main.async {
        height = textView.sizeThatFits(textView.visibleSize).height
    }
    

提交回复
热议问题