#import "ViewController.h"@interfaceViewcontroller () <UIWebViewDelegate>@property (Weak, nonatomic) Iboutlet UIWebView*WebView, @property (weak, nonatomic) Iboutlet Uibarbuttonitem*GoBack, @property (weak, nonatomic) Iboutlet Uibarbuttonitem*GoForward;@end@implementationViewcontroller#pragmaMark----------------------#pragmaMark Life cycle-(void) viewdidload{[Super Viewdidload]; Nsurl*url = [Nsurl urlwithstring:@"http://www.baidu.com"]; Nsurlrequest*request =[Nsurlrequest Requestwithurl:url]; //Loading Web pages[Self.webview loadrequest:request]; //Set up proxySelf.webview.Delegate=Self ;}#pragmaMark----------------------#pragmaMark Events-(Ibaction) Gobackbtnclick: (ID) sender{[Self.webview goBack];}-(Ibaction) Goforwardbtnclick: (ID) sender{[Self.webview GoForward]; }-(Ibaction) Reloadbtnclick: (ID) sender{[Self.webview reload];}#pragmaMark----------------------#pragmaMark Uiwebviewdelegate//called when a request is about to be loaded-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (Nsurlrequest *Request Navigationtype: (uiwebviewnavigationtype) navigationtype{NSLog (@"%@", request. url.absolutestring); //Simple request interception processingNSString *STRM =request. url.absolutestring; if([StrM containsstring:@" the"]) { returnNO; } returnYES;}//1. When you start loading a Web page, call-(void) Webviewdidstartload: (UIWebView *) webview{NSLog (@"Webviewdidstartload");}//2. Call when loading is complete-(void) Webviewdidfinishload: (UIWebView *) webview{NSLog (@"Webviewdidfinishload"); Self.goBack.enabled=Self.webView.canGoBack; Self.goForward.enabled=Self.webView.canGoForward;}//3. Call when the load fails-(void) WebView: (UIWebView *) WebView didfailloadwitherror: (Nserror *) error{NSLog (@"Didfailloadwitherror");}@end
# # # # #8 basic use of WebView
"' OBJC
1 Conceptual knowledge
The webview is flawed and can lead to memory leaks, and the problem is the problem with its system itself.
02 The Safai on the phone is actually implemented with WebView.
03 The present development is not entirely native development, but more inclined to native +HTML5 way
WebView is the bridge between the OC code and the HTML code
2 Code-related
/*a* Web page manipulation related methods **/
[Self.webview GoBack]; Fallback
[Self.webview GoForward]; Forward
[Self.webview Reload]; Refresh
Set whether you can forward and rewind
self.goBackBtn.enabled = Webview.cangoback;
self.fowardBtn.enabled = Webview.cangoforward;
/*b* commonly used property settings **/
Self.webView.scalesPageToFit = YES; Set Web page auto-fit
Self.webView.dataDetectorTypes = Uidatadetectortypeall; Sets the type of formatting in the detection Web page, all indicates that all types including hyperlinks, phone numbers, addresses, and so on are detected.
Self.webView.scrollView.contentInset = Uiedgeinsetsmake (50, 0, 0, 0);
/*c* Related Agent Method **/
Whenever the method is called when the request is loaded, the return yes indicates that the request is loaded and no indicates that the request is not loaded
The request can be intercepted in this method
-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) Navigationtype
{
Return! [Request. Url.absolutestring containsstring:@ "Dushu"];
}
Starts loading the Web page, not only listens to the request we specify, but also listens for internally sent requests
-(void) Webviewdidstartload: (UIWebView *) WebView
This method is called when the page is loaded
-(void) Webviewdidfinishload: (UIWebView *) WebView
Page load failed calling this method
-(void) WebView: (UIWebView *) WebView didfailloadwitherror: (nserror *) error
/*d* other knowledge points-load local resources **/
Nsurl *url = [[NSBundle mainbundle] urlforresource:@ "text.html" withextension:nil];
[Self.webview loadrequest:[nsurlrequest Requestwithurl:url];
```
# # # # #9 HTML
"' OBJC
1.Html determines the content of the Web page, CSS determines the style of the page, JS determines the events of the page
2.html Learning Website: http://www.w3school.com.cn
iOS Development WebView use two