UILabel sizetofit скрывает некоторые слова в приписанном тексте - PullRequest
0 голосов
/ 18 мая 2018

Атрибутивный текст имеет значение 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 голосов
/ 21 мая 2018

Вместо того, чтобы назначать приписанный текст метке, простой текст делает свое дело, получая строку из 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)
}
0 голосов
/ 18 мая 2018

Вам необходимо указать xAxis Положение вашего UILabel объекта, чтобы сделать его видимым на экране.

//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))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...