识别文本中图像、视频的html标签,并在动态放置时将其转换为图像、视频
在我的应用程序中,我需要放置一些从解析数据中获取的文本。目前我正在将它放在标签中。问题是,在该明文中将会有一些 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.
为图像下方。这应该在运行时发生。也可能有视频 url 代替图像 url。
提前致谢。
In my app I need to lay some text which I'm getting from a parsed data. Currently I'm currently laying it in a label. The problem is there are going to be some html tags indicating an image [along with its url] and videos etc in that plaintext. What is a good way to handle this identifying images and videos tags and laying corresponding images and videos along with rest of the plaintext dynamically?
EDIT:
Suppose I'm having following text
<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.
Then while displaying I want to display an image indicated by the url in place of
<img alt="" src="http://www.abc.com/editorial/wp-content/uploads/2010/05/hattoss-150x150.jpg" title="Graduation" class="alignnone" width="150" height="150" />
and
display
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.
as it is below the image. And this should happen at runtime. There might also be a video url in place of image url.
Thanx in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您看到“img”元素,请创建自定义
DetailView
。在“详细信息”视图中,使用[[element attribute] objectForKey:@"src"]; 传递将在“img”元素的 attribute 属性中找到的地址;
使用该地址下载并填充UIImage
。中的内容是元素(示例中缺少块标签)可以传递给
UILabel
或UITextView
(以合适的为准)。如果您看到视频标签,请使用带有“src”属性的initWithContentURL:
创建一个MPMoviePlayerController
并将其推送到视图堆栈上。If you see an "img" element, create your custom
DetailView
. In your "detail" view, pass the address in which will be found in the attributes property of the "img" element using[[element attributes] objectForKey:@"src"];
Use the address to download and populate aUIImage
. The contents in the <p> element (the block tags are missing in your example) can be passed to aUILabel
orUITextView
whichever is appropriate. If you see a video tag, create anMPMoviePlayerController
usinginitWithContentURL:
with the "src" attribute and push onto the view stack.