本文介绍了如何在UIWebView中加载HTML文件的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用以下几行代码在UIWebView中加载HTML文件:
NSString * htmlFile = [[NSBundle mainBundle] pathForResource:@01NumbersofType:@html];
NSURL * url = [NSURL fileURLWithPath:htmlFile];
NSURLRequest * request = [NSURLRequest requestWithURL:url];
[WebView loadRequest:request];
我可以加载HTML文件,但这个HTML文件也包含一些图片,不能在视图中加载/可见,任何人都可以为此提出任何解决方案?
解决方案
HTML文件:
< HTML>
< HEAD>
< TITLE>我的网页< / TITLE>
< / HEAD>
< BODY>
< img alt =src =1.jpgstyle =width:100px; height:100px;/>
< P>您可以在此输入想要在浏览器窗口中显示的所有文字和图片。< / P>
< / BODY>
< / HTML>
webView代码:
NSString * htmlFile = [[NSBundle mainBundle] pathForResource:@deskofType:@html];
NSURL * url = [NSURL fileURLWithPath:htmlFile];
NSURLRequest * request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
截图:
I want to load an HTML file in an UIWebView using following lines of code:
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"01Numbers" ofType:@"html"];
NSURL *url=[NSURL fileURLWithPath:htmlFile];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[WebView loadRequest:request];
I am able to load the HTML file, but this HTML file also contain some images, and that images are not loading/visible in the view, can anyone suggest any solution for this?
解决方案
HTML File:
<HTML>
<HEAD>
<TITLE>My Web Page</TITLE>
</HEAD>
<BODY>
<img alt="" src="1.jpg" style="width: 100px; height: 100px;"/>
<P>This is where you will enter all the text and images you want displayed in a browser window.</P>
</BODY>
</HTML>
webView code:
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"desk" ofType:@"html"];
NSURL *url=[NSURL fileURLWithPath:htmlFile];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
screenshot:
这篇关于如何在UIWebView中加载HTML文件的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!