How can I load a local HTML file into the UIWebView?

前端 未结 7 981
有刺的猬
有刺的猬 2020-12-09 03:17

How can we load our own html file into the UIWebView?

7条回答
  •  一个人的身影
    2020-12-09 03:33

    Cody Gray is right but there's also this way :

    // Load the html as a string from the file system
    NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
    NSString *html = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    
    // Tell the web view to load it
    [WebView loadHTMLString:html baseURL:[[NSBundle mainBundle] bundleURL]];
    

    This is useful if you need to edit the html before you load it.

提交回复
热议问题