Reputation: 119
If i have a WebView is there when a way i can make it show a line of HTML code or read a HTML document from the "Supporting Files" folder and then display it?
The important thing is just that it don't require the file to be somewhere else (the app needs to be standalone).
Thanks :-)
Upvotes: 0
Views: 321
Reputation: 483
Yes you can. The code I use for my webView is as follows:
NSString *fullURL = [[NSBundle mainBundle] pathForResource:@"webpage" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
You just put your html page in the main bundle of your application. Good Luck.
Upvotes: 1
Reputation: 18290
Yes! Check out loadHTMLString:baseURL:
. The trick to learn is that baseURL can begin with file://
;-)
With a "local" baseURL, all relative URLs in your markup and CSS (thing image resources, etc.) will be relative to that directory.
Upvotes: 2