美文网首页
【iOS开发】UILabel显示html标签的高度计算

【iOS开发】UILabel显示html标签的高度计算

作者: 文刂Rn | 来源:发表于2019-04-02 13:33 被阅读0次
    //富文本
            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)
    

    相关文章

      网友评论

          本文标题:【iOS开发】UILabel显示html标签的高度计算

          本文链接:https://www.haomeiwen.com/subject/oltgbqtx.html