UILabel加载图片文字HTML

2019-01-25  本文已影响9人  姚姚先生

加载文字没问题

NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[newHtmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute :@(NSUTF8StringEncoding) } documentAttributes:nil error:nil];
    self.contentLabel.attributedText = attrStr;

加载图片会超出边界
加上下面代码可以解决

NSString *newHtmlString= [NSString stringWithFormat:@"<head><style>img{width:%f !important;height:auto}</style></head>%@",KScreenWidth,htmlString];
上一篇 下一篇

猜你喜欢

热点阅读