ios HTML富文字設定圖片大小
阿新 • • 發佈:2018-11-29
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;