-
-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AsyncTextAttachment并不能很好的支持UILabel, 将Demo中的UITextView替换成UILabel, 无法显示图片, #142
Comments
"UILabel uses an internal NSLayoutManager for laying out the text and drawing it. Unfortunately Apple does not provide a property for us to access or customize it." Source I use a trick reload
Hope it helps! |
Hi @Bochbo, |
Hello, @midhunmgopal Call Code example
class ViewController: UIViewController {
private let label = UILabel()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .black
configureLabel()
let imageURL = "https://shorturl.at/GNV01"
let attributedString = NSMutableAttributedString(imageURL: imageURL, delegate: self)
label.attributedText = attributedString
}
private func configureLabel() {
view.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
label.topAnchor.constraint(equalTo: view.topAnchor, constant: 16),
label.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
label.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -16),
label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
])
}
}
extension ViewController: AsyncTextAttachmentDelegate {
func textAttachmentDidLoadImage(textAttachment: AsyncTextAttachment,
displaySizeChanged: Bool) {
label.reloadAttributedText()
}
}
extension UILabel {
func reloadAttributedText() {
let attr = attributedText
attributedText = nil
attributedText = attr
}
} |
Thank you so much @Bochbo ... |
UILabel:
UITextView:
The text was updated successfully, but these errors were encountered: