iOS UILabel NSAttributed String(带有span标签)在底部获得了过多空间

时间:2018-09-13 12:42:54

标签: ios swift nsattributedstring

我的扩展名为get

NSAttributedString

并且在tableCell中有标签,其中我要添加属性HTML内容字符串,例如

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
        }
    }
}

但是在运行时,我遇到了红色标记所示的空间问题

enter image description here

我如何删除该空间?

0 个答案:

没有答案