Changed AttributedStringView to use UITextView

This commit is contained in:
Maurice Parker
2019-10-20 14:29:28 -05:00
parent 3ca0934ecb
commit 3a359f0e37
2 changed files with 19 additions and 11 deletions

View File

@@ -13,17 +13,18 @@ struct AttributedStringView: UIViewRepresentable {
let string: NSAttributedString
let preferredMaxLayoutWidth: CGFloat
func makeUIView(context: Context) -> UILabel {
return UILabel()
func makeUIView(context: Context) -> HackedTextView {
return HackedTextView()
}
func updateUIView(_ view: UILabel, context: Context) {
func updateUIView(_ view: HackedTextView, context: Context) {
view.attributedText = string
view.numberOfLines = 0
view.lineBreakMode = .byWordWrapping
view.preferredMaxLayoutWidth = preferredMaxLayoutWidth
view.isScrollEnabled = false
view.textContainer.lineBreakMode = .byWordWrapping
view.isUserInteractionEnabled = true
view.adjustsFontForContentSizeCategory = true
view.font = .preferredFont(forTextStyle: .body)
view.textColor = UIColor.label
@@ -35,3 +36,10 @@ struct AttributedStringView: UIViewRepresentable {
}
}
class HackedTextView: UITextView {
var preferredMaxLayoutWidth = CGFloat.zero
override var intrinsicContentSize: CGSize {
return sizeThatFits(CGSize(width: preferredMaxLayoutWidth, height: .infinity))
}
}