How To Load Images With Html File In Uiwebview
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=[NSU
Solution 1:
HTML File:
<HTML><HEAD><TITLE>My Web Page</TITLE></HEAD><BODY><imgalt=""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:
Solution 2:
You can use following way to load HTML file,
In this way all content get converted into Data and will load in webView. (All UI related contents like images icons should be in Resources Dir of project)
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"FileName" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
if (htmlData)
{
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:nil];
}
Solution 3:
I assume the images are also in the bundle. You will have to make sure the path set on the tag is a reference to the location of the image file IN the bundle or wherever you are storing that.
Solution 4:
Maybe you should try to put all you local webpage in a folder and use
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"01Numbers" ofType:@"html" inDirectory:@"Your directory"];
Post a Comment for "How To Load Images With Html File In Uiwebview"