在Iphone上的UIWebView中加载内容 [英] Load Content in the UIWebView on the Iphone
问题描述
Helllo,
我想在UIWebView中显示内容,
我已添加到项目中。
例如图像。
我知道如何在UIWebView中设置文本,但我想添加我已添加到项目中的图像或视频
Helllo, i would like to show Content in the UIWebView, which i have added to the Project. for example an image. I know how to set a text in the UIWebView, but i would like to add images or a video which i have added to the project
最好的问候,
推荐答案
好的,我假设您正在使用 loadHTMLString 在上设置HTML的UIWebView 。
Ok, I am assuming you are using loadHTMLString to set the HTML on your UIWebView.
因此,要引用存储在App捆绑包中的图像,您只需要获得放入img标记的正确路径。所以得到路径字符串:
So to reference images that are stored in your App bundle, you just need to get the right path to put in your img tag. So get the path string:
NSString * imgPath = [[NSBundle mainBundle] pathForResource:nameOfImage ofType:@"jpg"];
使用图片代码格式化一些HTML:
Format some HTML with an image tag:
NSString * html = NSString [[[NSString alloc] initWithFormat:@"<img src=\"file://%@\"/>", imgPath] autorelease];
然后在网页视图中设置HTML:
Then set your HTML on the web view:
[self.webView loadHTMLString:html baseURL:nil];
您只需将图像添加到您的应用资源( nameOfImage in上面的代码),它会工作正常。
You just need to add the images to your app resources (nameOfImage in the code above) and it will work fine.
这篇关于在Iphone上的UIWebView中加载内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!