Uiwebview can load by URL or HTML string. That is, you can generate HTML string by yourself to use Web View display. A typical application of load HTML string is: the URL corresponds to too many web pages. If you only need part of the HTML content, you can get the HTML content of the URL through HTTP request, then, select only the desired part and display it by load HTML string.
Sometimes, you cannot avoid using local CSS, JS, or image (of course, you can also use URLs to link to CSS/JS/image on the Internet ).
Assume that a webpage.css and a test. js have been stored in resource folder in your iOS app, then the HTML string you generated should include them like this.
Nsstring * htmlheader = @ "<HTML> Src = 'test. js'> </SCRIPT>
Nsstring * htmlbody = @ "<p> </P> ";
Nsstring * htmlfooter = @ "</body>
Nsstring * strhtml = [[nsstring
Alloc] initwithformat: @ "% @", htmlheader, htmlbody, htmlfooter];
[Webview
Loadhtmlstring: strhtml
Baseurl: [nsurl
Fileurlwithpath: [[nsbundle
Mainbundle] resourcepath]
Isdirectory: Yes]];
Note:
1. baseurl is your resource folder path
2. if <SCRIPT type = 'text/JavaScript 'charset = 'utf-8' src = 'test. JS '> </SCRIPT> to <SCRIPT type = 'text/JavaScript' charset = 'utf-8' src = 'test. JS '/>, you cannot load JS (ref
Link:
Http://stackoverflow.com/questions/7840127/uiwebview-loadhtmlstring-not-working-in-ios5)
3. when you create Js in IOS project or add JS, by default. by default, JS files will be compiled as code (you will see warning when building a project), so you need. JS files from "compile sources" move to "Copy bundle resources", see