//富文本
let attrStr = try! NSMutableAttributedString(
data: (answer.content.data(using: .unicode, allowLossyConversion: true)!),
options:[.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue],
documentAttributes: nil)
//行高
let paraph = NSMutableParagraphStyle()
paraph.lineSpacing = 8
attrStr.addAttributes([NSAttributedStringKey.paragraphStyle:paraph],
range: NSMakeRange(0, attrStr.length))
self.answerLabel.attributedText = attrStr
//计算高度
let size:CGRect = attrStr.boundingRect(with: CGSize(width: SCREENWIDTH-32, height: CGFloat(MAXFLOAT)), options: NSStringDrawingOptions(rawValue: NSStringDrawingOptions.usesLineFragmentOrigin.rawValue), context: nil)
网友评论