UITextView加载html字符串,图片不能自适应的解决方法

UITextView中,加载服务器返回的html字符串,用到的方法为

+ (NSMutableAttributedString *)attributedStringWithHTMLString:(NSString *)htmlStr withFont:(UIFont *)font {
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:[[NSString stringWithFormat:@" %@",htmlStr] dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute :@(NSUTF8StringEncoding)} documentAttributes:nil error:nil];
    [attributedString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, attributedString.length)];
    return attributedString;
}

但是图片没有展示完全


image.png

添加图片自适应的html语句

    NSString *adaptString = [NSString stringWithFormat:@"%@", self.contentTextView.width, self.currentVideo.content];

这样图片显示就正常了


image.png

参考文档:
https://www.jianshu.com/p/7d604f360d9a

你可能感兴趣的:(UITextView加载html字符串,图片不能自适应的解决方法)