iOS UILabel NSAttributed String with span tag getting excessive space in bottom

故事扮演 提交于 2020-01-06 05:36:05

问题


I have a extension of NSAttributedString

extension NSAttributedString {

    convenience init?(htmlString: String, font: UIFont, colorCode: String) {
        let styledHTMLString = "<span style=\"font-family:\(font.fontName); color:\(colorCode) ;font-size:\(font.pointSize)px\">\(htmlString)</span>"
        guard let data = styledHTMLString.data(using: String.Encoding.utf8) else { return nil }
        do {
            try self.init(data: data,
                          options: [.documentType: NSAttributedString.DocumentType.html,
                                    .characterEncoding: NSNumber(value: String.Encoding.utf8.rawValue)],
                          documentAttributes: nil)
        } catch {
            return nil
        }
    }
}

and I have label in tableCell in which i'm adding attributed HTML content string like

    let attributedText = NSAttributedString(htmlString: htmlContent,
                                            font: UIFont.focoRegular(16.0),
                                            colorCode: "464646")
    self.descriptionLabel.attributedText = attributedText

But in runtime i'm facing space issue as shown in red mark

How i can remove this space?

来源:https://stackoverflow.com/questions/52314006/ios-uilabel-nsattributed-string-with-span-tag-getting-excessive-space-in-bottom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!