我DTAttributedTextContentView
在 UITableViewCell 中并尝试使用 html(带图像)加载它,但找不到合适的方法来执行此操作。我DemoTextViewController.m
在 Demo 中查看了具有图像加载的
- (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
大小。我找不到任何关于如何实现这一点的文档。
如果您有更好的选择或解决方案,请告诉我。