Как показать изображение в UITableViewCell с помощью DTCoreText
я имею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
размер. Я могу'Не могу найти какой-либо документ о том, как это реализовать.
Если у вас есть лучший выбор или решение, пожалуйста, скажите мне.