Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eiffelqiu/988227 to your computer and use it in GitHub Desktop.
Save eiffelqiu/988227 to your computer and use it in GitHub Desktop.
Load assets in webview
// Load html from local file
NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"localpage" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",imagePath]]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment