美文网首页
iOS 加载html图片修改图片大小

iOS 加载html图片修改图片大小

作者: Flora_HAHA | 来源:发表于2019-10-14 12:07 被阅读0次
     //html修改图片大小
     //label.font.lineHeight: 图片宽度
        let imgSize = "<head><style>img{width:\(label.font.lineHeight)!important;height:auto}</style></head>"
        let myRichText = imgSize + content
        let emotionStr = try! NSMutableAttributedString.init(data: (myRichText.data(using: String.Encoding.unicode))!, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html], documentAttributes: nil)
        emotionStr.addAttribute(NSAttributedString.Key.font , value: label.font!, range: NSRange.init(location: 0, length: emotionStr.length))
        label.attributedText = emotionStr
    

    相关文章

      网友评论

          本文标题:iOS 加载html图片修改图片大小

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