【问题标题】:Identify html tags for image, video in text and convert them into images, videos while laying dynamically在文本中识别图像、视频的 html 标签,并在动态放置时将它们转换为图像、视频
【发布时间】:2010-06-18 06:26:16
【问题描述】:

在我的应用程序中,我需要放置一些从解析数据中获取的文本。目前我正在将它放在标签中。问题是会有一些 html 标签在该明文中指示图像 [连同其 url] 和视频等。处理这种识别图像和视频标签并将相应的图像和视频与其余明文动态放置的好方法是什么?

编辑:

假设我有以下文字

<img alt="" src="http://www.abc.com/editorial/wp-content/uploads/2010/05/hattos-150x150.jpg" title="Graduation" class="alignnone" width="150" height="150" />
For many, graduation is the time when they start thinking of their career planning.    Many of you know that they want to make a difference, but don't know how to go past that statement.

然后在显示时我想显示一个由 url 指示的图像来代替

<img alt="" src="http://www.abc.com/editorial/wp-content/uploads/2010/05/hattoss-150x150.jpg" title="Graduation" class="alignnone" width="150" height="150" />

和 显示

For many, graduation is the time when they start thinking of their career planning.    Many of you know that they want to make a difference, but don't know how to go past that statement.

因为它在图像下方。这应该在运行时发生。也可能有一个视频网址代替图片网址。

提前感谢。

【问题讨论】:

  • 这个问题对我来说不是很清楚。你得到什么样的数据?为什么有网址?那个标签是什么?可以发一个示例代码库来理解吗?
  • 我得到的数据是明文数据。在该数据中,将嵌入标签,例如 MyImage 之类的图像标签。因此,在显示文本时,我需要保持纯文本数据不变,并将 html 标记中指示的图像显示为图像。这应该在运行时发生。
  • @neha 首先,img 元素没有结束标记 (),因此图像标记无论如何都不会包含这样的文本。不过,您可以使用替代文本。你的问题还不清楚。您是否想说“您如何显示图像使其替代文本也显示在页面上?”
  • @Evan Plaice 你说的对,img 元素没有结束标签。感谢您纠正我。请检查我编辑的问题。
  • @neha 我想我想念的是,你到底想创造什么?

标签: iphone html dynamic-data


【解决方案1】:

如果您看到“img”元素,请创建您的自定义DetailView。在您的“详细信息”视图中,使用[[element attributes] objectForKey:@"src"]; 传递将在“img”元素的属性属性中找到的地址。使用该地址下载并填充UIImage

元素中的内容(您的示例中缺少块标记)可以传递给UILabelUITextView,无论哪个合适。如果您看到视频标签,请使用带有“src”属性的initWithContentURL: 创建一个MPMoviePlayerController,然后推送到视图堆栈。

【讨论】:

    猜你喜欢
    • 2020-11-10
    • 1970-01-01
    • 2016-12-22
    • 2012-06-08
    • 1970-01-01
    • 2017-02-26
    • 2018-07-16
    • 1970-01-01
    相关资源
    最近更新 更多