富文本加載html代碼的時(shí)候可能會出現(xiàn)圖片過大淳附,沒有辦法控制打洼。下面這種處理方法可以解決
直接把這段代碼拼接上就可以了@"<head><style>img{width:100px !important;height:auto}</style></head>"
如果需要修改其他的樣式,根據(jù)此方法依次類推就可以的玩焰,demo如下所示:
UILabel *detailLab = [[UILabel alloc] init];
detailLab.numberOfLines = 0;
[_tableHeaderView addSubview:detailLab];
NSString *detailTextString = [NSString stringWithFormat:@"%@",_headerDataDic[@"art_content"]];
NSString *str = [NSString stringWithFormat:@"<head><style>img{width:%f !important;height:auto}</style></head>%@",self.view.width - 30,detailTextString];
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
detailLab.attributedText = attributeString;