gpt4 book ai didi

html - UILabel sizetofit 隐藏了属性文本中的一些单词

转载 作者:行者123 更新时间:2023-11-30 11:29:26 25 4
gpt4 key购买 nike

属性文本设置为 UILabel。

let label = UILabel()
label.frame = view.frame
label.numberOfLines = 0
do {
let spannableString = try NSAttributedString(data: htmlString.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType], documentAttributes: nil)
label.attributedText = spannableString
} catch {
print(error)

}
label.lineBreakMode = NSLineBreakMode.byWordWrapping
label.sizeToFit()
self.view.addSubview(label)

有些文本不可见。即,文本末尾的某些单词被截断/不可见。属性文本由以下 HTML 字符串组成。

<span style="line-height&#58;1.4em;">HE Ahmed Mohamed Al Humairi, Secretary General of MoPA and Chairman of the Emirates Palace Company (EPCo), held a meeting attended by the board members and the General Manager of the Emirates Palace hotel. &#160;In the course of the meeting, a committee was formed to prepare for the 42nd National Day celebrations in a style that will highlight the importance of such a national event and reflect the culturally-developed status of Abu Dhabi. &#160;</span><br><div><br></div><div>The meeting also reviewed the latest developments in the ongoing projects aimed at maintaining the pioneering role played by the Emirates Palace in being both one of the best hotels in the world and one of the most important metropolitan landmarks in Abu Dhabi. &#160;</div><div><br></div><div>The board discussed a set of new projects and future events that will serve to enhance the role of the Emirates Palace Hotel in helping to stimulate tourism and the economy. &#160;</div>

我尝试添加垂直约束

self.view.addConstraint(NSLayoutConstraint(item: label,
attribute: .centerY,
relatedBy: .equal,
toItem: self.view,
attribute: .centerY,
multiplier: 1.0,
constant: 0.0))

但运气不佳。谁能提出这个问题的解决方案?

最佳答案

您需要提供 UILabel 对象的 xAxis 位置,以便在屏幕上可见。

//Taking Leading Constraint as X-Axis constraint.

self.view.addConstraint(NSLayoutConstraint(item: label,
attribute: .leading,
relatedBy: .equal,
toItem: self.view,
attribute: .leading,
multiplier: 1.0,
constant: 0.0))

关于html - UILabel sizetofit 隐藏了属性文本中的一些单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50408712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com