我有DTAttributedTextContentView
在UITableViewCell中,并尝试用HTML(含图片)来加载它,但无法找到一个合适的方式来做到这一点。 我有考虑DemoTextViewController.m
在演示具有图像负载
- (void)lazyImageView:(DTLazyImageView *)lazyImageView didChangeImageSize:(CGSize)size {
NSURL *url = lazyImageView.url;
CGSize imageSize = size;
NSPredicate *pred = [NSPredicate predicateWithFormat:@"contentURL == %@", url];
// update all attachments that matchin this URL (possibly multiple images with same size)
for (DTTextAttachment *oneAttachment in [_textView.attributedTextContentView.layoutFrame textAttachmentsWithPredicate:pred])
{
oneAttachment.originalSize = imageSize;
if (!CGSizeEqualToSize(imageSize, oneAttachment.displaySize))
{
oneAttachment.displaySize = imageSize;
}
}
// redo layout
// here we're layouting the entire string, might be more efficient to only relayout the paragraphs that contain these attachments
[_textView.attributedTextContentView relayoutText];
}
但我不知道这将如何应用到的UITableViewCell我试着
- (void)lazyImageView:(DTLazyImageView *)lazyImageView didChangeImageSize:(CGSize)size {
NSURL *url = lazyImageView.url;
CGSize imageSize = size;
NSPredicate *pred = [NSPredicate predicateWithFormat:@"contentURL == %@", url];
for (UITableViewCell *cell in self.tableView.visibleCells) {
if ([cell isKindOfClass:[CommentCell class]]) {
CommentCell *cc = (CommentCell *)cell;
for (DTTextAttachment *oneAttachment in [cc.attributedTextContentView.layoutFrame textAttachmentsWithPredicate:pred])
{
oneAttachment.originalSize = imageSize;
if (!CGSizeEqualToSize(imageSize, oneAttachment.displaySize))
{
oneAttachment.displaySize = CGSizeMake(300, 100);
}
}
[cc.attributedTextContentView relayoutText];
}
}
}
但是,单元格的高度无法正确显示和图像不调整大小以适应DTAttributedTextContentView
大小。 我找不到如何实现此的任何文件。
如果你有更好的选择或解决方案,请告诉我。