First, use UIWebView to embed Web content on your app.
The API provides three ways to:
- -(void) Loadrequest: (nsurlrequest *) request;
- -(void) loadhtmlstring: (NSString *) string BaseURL: (Nsurl *) BaseURL;
- -(void) LoadData: (NSData *) data MIMEType: (NSString *)
- MIMEType textencodingname: (NSString *) textencodingname BaseURL: (Nsurl *) BaseURL;
1, give the URL address directly to load the Web content.
- NSString *Path = @ "http://theo2life.com";
- Nsurl *URL = [[Nsurl alloc] initwithstring:path];
- [Self.webview loadrequest:[nsurlrequest Requestwithurl:url];
2. Embed local HTML file contents into WebView
- NSString *ResourcePath = [[NSBundle mainbundle] resourcepath];
- NSString *FilePath = [ResourcePath stringbyappendingpathcomponent:@ "test.html"];
- NSString *htmlstring =[[nsstring alloc] Initwithcontentsoffile:filepath encoding:nsutf8stringencoding Error : nil];
- [Self.webview loadhtmlstring:htmlstring baseurl:[nsurl fileurlwithpath: [[NSBundle Mainbundle] bundlePath]];
You can also do this if you do not load from an HTML file:
- NSString *HTMLData = @ " src=\" test2.png\ " />ddd";
- [Self.webview loadhtmlstring:htmldata baseurl:[nsurl fileurlwithpath: [[NSBundle Mainbundle] bundlePath]];
- Baseurl:[nsurl Fileurlwithpath: [[NSBundle Mainbundle] Bundlepath]
This paragraph indicates the basic path of other file resources referenced by HTMLData, if the Baseurl:nil picture information will not be displayed ~
3, the same 2, in more detail gives the Web content encoding method.
Second, other operations:
If the loaded Web layout is larger than the size of the ipad, the part that is found to be out is blank, set webview.scalespagetofit = YES, and make the Web content layout adaptable to WebView.
Three ways to load UIWebView