How do I make sure my UIViewRepresentable
has the same width as it's parent? I have created a representable class for a UILabel
with an attributed text (converted from HTML).
AttributedLabel.swift
:
struct AttributedLabel: UIViewRepresentable {
let attributedText: NSAttributedString
func makeUIView(context: UIViewRepresentableContext<Self>) -> UILabel {
let label = UILabel()
label.attributedText = attributedText
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
label.backgroundColor = UIColor.red
return label
}
func updateUIView(_ uiView: UILabel, context: UIViewRepresentableContext<Self>) {}
}
Usage example:
List {
VStack {
AttributedLabel(attributedText: attributedText)
}
}