Atributika
Atributika copied to clipboard
AttributedLabel height not set in SwiftUI List
Maybe I'm doing something wrong, but I'm having issues setting the height of a multi-line AttributedLabel when it's in a SwiftUI List or ScrollView.
Please refer to this minimal reproducible example
It works perfectly fine when I use a UITextView or a UILabel but I need to handle touches on html links.
Hi,
Works for me if set translatesAutoresizingMaskIntoConstraints to false
struct HTMLViewAttributedLabel: UIViewRepresentable {
let html: String
func makeUIView(context: Context) -> AttributedLabel {
let all = Style.font(.systemFont(ofSize: 16))
let link = Style("a")
.foregroundColor(.systemTeal, .normal)
.foregroundColor(.systemTeal, .highlighted)
let attributedText = html
.style(tags: link)
.styleLinks(link)
.styleAll(all)
let label = AttributedLabel()
label.attributedText = attributedText
label.numberOfLines = 0
label.translatesAutoresizingMaskIntoConstraints = false
return label
}
func updateUIView(_ uiView: AttributedLabel, context: Context) {
}
}
any update?
I defined a variable on swiftUI side @State var size:CGSize = .zero and I binded size to this view self.size = label.sizeThatFits(label.superview?.bounds.size ?? .zero) and I can use size like this : .frame(width: size.width , height: size.height)
Please check a SwiftUI example in the demo project