直接代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.textLabel.numberOfLines = 0; UIFont *font=[UIFont systemFontOfSize:14]; NSDictionary *optoins=@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSFontAttributeName:font}; NSData *data=[self.lectorContent dataUsingEncoding:NSUnicodeStringEncoding]; NSAttributedString *attributeString=[[NSAttributedString alloc] initWithData:data options:optoins documentAttributes:nil error:nil]; cell.textLabel.attributedText=attributeString; return cell; }
备注:当图片超出屏幕时,可以在html代码中添加样式如:
<head><style>img{width:%f !important;height:auto}</style></head>
注意此方法不是万能的,比如:图文是内嵌型的就不适合这种方式