【问题标题】:iOS: Can HTMLReader load embedded images?iOS:HTMLReader 可以加载嵌入的图像吗?
【发布时间】:2015-07-28 08:29:06
【问题描述】:

我正在开发一个从 url (JSON) 获取其内容的 iOS 新闻应用程序。

在文章的详细信息 ViewController 中,我制作了一个标签来显示描述,假设我有以下字符串,应用程序将从 JSON 对象获取以下字符串(形成一个 url):

"bla bla bla <div>another bla bla bla</div><img src="some_image_src" />
bla bla blabla <strong>bla</strong>"

我正在使用HTMLReader 删除 html 标签,除了字符串中的图像外,一切看起来都很好,我如何显示嵌入的图像?

提前致谢。

注意: HTMLReader 文档很短,他们没有说明任何关于图像标签的内容

【问题讨论】:

    标签: ios objective-c html-parsing


    【解决方案1】:

    使用您的 url 下载图像数据并使用 NSMutableAttributedString:

    NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    attachment.image = [UIImage imageNamed:@"whatever"];
    NSAttributedString *attributedString = [NSAttributedString attributedStringWithAttachment:attachment];
    yourTextView.attributedText = attributedString;
    

    【讨论】:

      猜你喜欢
      • 2011-02-11
      • 1970-01-01
      • 1970-01-01
      • 2013-09-15
      • 1970-01-01
      • 2012-01-03
      • 2011-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多