Display a multi-line NSAttributedString
in SwiftUI
Search around the web and implemented a UIViewRepresentable
:
struct AttributedText: UIViewRepresentable {
var text: NSAttributedString
func makeUIView(context: Context) -> UILabel {
let label = UILabel()
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping
return label
}
func updateUIView(_ label: UILabel, context: Context) {
label.attributedText = text
}
}
The label shows only one, long line of text. A UITest to check for the correct behavior is included
Any idea what I could do?