iOS中设置HTML富文本是,图片太大显示不全,这个时候需要修改CSS样式,。
NSString *contentStr = [NSString stringWithFormat:@"<head><style>img{width:%f !important;height:auto;}</style></head>%@",self.view.width-50,self.detailModel.imgtextguidance];
NSMutableAttributedString *attriStr= [[NSMutableAttributedString alloc] initWithData:[contentStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
[attriStr addAttribute:NSFontAttributeName value:SYSTEM_FONT(15) range:NSMakeRange(0, attriStr.length)];
[attriStr addAttribute:NSForegroundColorAttributeName value:BlackColor range:NSMakeRange(0, attriStr.length)];
self.contentLabel.numberOfLines = 0;
self.contentLabel.attributedText = attriStr;