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

时间:2018-05-18 09:58:56

标签: html ios swift string uilabel

属性文本设置为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))

但没有运气。有人可以为这个问题提出解决方案吗?

2 个答案:

答案 0 :(得分:0)

您需要提供curl -k -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" -d "grant_type=password&username=abc\@test\.com&password=ChangeMe\!\@\#&scope=openid" https://<cluster_access_ip>:8443/idprovider/v1/auth/identitytoken --insecure 对象的xAxis位置才能在屏幕上显示。

UILabel

答案 1 :(得分:0)

简单文本不是将属性文本设置为标签,而是通过从attributedString

获取字符串来实现
do {
    let spannableString = try NSAttributedString(data: htmlString.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType], documentAttributes: nil)
    label.text = spannableString.string
} catch {
    print(error)
}