Load image in local HTML file — UIWebView

前端 未结 1 2028
挽巷
挽巷 2020-12-18 16:13

I load a local HTML file in a UIWebView like so:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResou         


        
相关标签:
1条回答
  • 2020-12-18 16:24

    Instead of loading with an NSURLRequest, read the html file into an NSString and create an NSURL to the directory with image files.

    Then use UIWebView's - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL method.

    So, you'd have something like...

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
    NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    
    [webView loadHTMLString:html baseURL:[url URLByDeletingLastPathComponent]];
    
    0 讨论(0)
提交回复
热议问题