iOS Development Network Chapter-uiwebview Brief Introduction

Source: Internet
Author: User

iOS Development Network Chapter-uiwebview Brief Introduction

First, Brief introduction

1. Brief description

UIWebView is an iOS built-in browser control
The system comes with a safari browser that is implemented through UIWebView

UIWebView not only can load remote Web resources, but also can load the most common Files html\htm pdf, doc, ppt, txt mp4 ...

2.UIWebView How to load resources

-(void) Loadrequest: (nsurlrequest *) request;

3. Common Properties and methods

Reload (refresh)-(void) reload;

Stop loading -(void) stoploading;

Fallback -(void) goBack;

Forward-(void) GoForward;

Need to go in? detected data type @property (nonatomic) uidatadetectortypes datadetectortypes

Whether it can be rolled back @property (nonatomic,readonly,getter=cangoback) BOOL cangoback;

Whether it can advance @property (nonatomic,readonly,getter=cangoforward) BOOL CanGoForward;

Whether the @property (nonatomic,readonly,getter=isloading) BOOL loading is being loaded;

Whether to scale the content to fit the screen current size @property (nonatomic) BOOL scalespagetofit;

4. Monitor the UIWebView loading process

Become the agent of UIWebView, obey the Uiwebviewdelegate protocol, can monitor the loading process of UIWebView.

Call this method when you start sending a request (loading data)

-(void) Webviewdidstartload: (UIWebView *) WebView;

Request complete (Load data complete) Si cho? This method

-(void) Webviewdidfinishload: (UIWebView *) WebView;

Call this method when an error is requested

-(void) WebView: (UIWebView *) WebView didfailloadwitherror: (nserror *) error;

5. Monitor the UIWebView loading process

UIWebView before sending the request, will it be transferred? method, if return no, represents a stop load request, returns Yes, representing the Allow load request

-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) Navigationtype;

Second, basic use

1. Example One

Create a new project and drag a Uiwedview control in the UIView in storyboard.

The simplest to use:

(1) Create a network request

(2) Load network request

Code:

1 //2 //YYVIEWCONTROLLER.M3 //Basic use of 01-uiwebview4 //5 //Created by Hole Medical has on 14-7-2.6 //Copyright (c) 2014 itcast. All rights reserved.7 //8 9 #import "YYViewController.h"Ten  One @interfaceYyviewcontroller () A@property (Weak, nonatomic) iboutlet UIWebView *WebView; -  - @end the  - /** - * UIWebView: Browser, can be used to browse common format files, such as Html/txt/doc/ppt/mp4, etc. -  */ + @implementationYyviewcontroller -  +- (void) Viewdidload A { at [Super Viewdidload]; -      -     //1. Create a network request -Nsurl *url=[nsurl urlwithstring:@"http://www.baidu.com"]; -Nsurlrequest *request=[Nsurlrequest Requestwithurl:url]; -      in     //Load Network Requests - [Self.webview loadrequest:request]; to      + } -  the @end

Simulator Effect:

2. Monitoring UIWebView

code example:

1 //2 //YYVIEWCONTROLLER.M3 //Basic use of 01-uiwebview4 //5 //Created by Hole Medical has on 14-7-2.6 //Copyright (c) 2014 itcast. All rights reserved.7 //8 9 #import "YYViewController.h"Ten //using a third-party framework One #import "mbprogresshud+mj.h" A  - @interfaceYyviewcontroller () <UIWebViewDelegate> -@property (Weak, nonatomic) iboutlet UIWebView *WebView; the  - @end -  - /** + * UIWebView: Browser, can be used to browse common format files, such as Html/txt/doc/ppt/mp4, etc. -  */ + @implementationYyviewcontroller A  at- (void) Viewdidload - { - [Super Viewdidload]; -      -     //1. Create a network request -Nsurl *url=[nsurl urlwithstring:@"http://www.baidu.com"]; inNsurlrequest *request=[Nsurlrequest Requestwithurl:url]; -      to     //2. Setting up the WebView agent +Self.webview.Delegate=Self ; -     //scaling content to fit the screen size theself.webview.scalespagetofit=YES; *      $     //Load Network RequestsPanax Notoginseng [Self.webview loadrequest:request]; -      the } +  A #pragmaMark-uiwebviewdelegate the /** + *webview When the resource starts to load (start sending request) -  */ $-(void) Webviewdidstartload: (UIWebView *) WebView $ { -NSLog (@"webviewdidstartload---"); -[Mbprogresshud ShowMessage:@"Loading ..."]; the } - Wuyi /** the *webview when loading is complete (request completed) -  */ Wu-(void) Webviewdidfinishload: (UIWebView *) WebView - { AboutNSLog (@"webviewdidfinishload---"); $ [Mbprogresshud Hidehud]; - } -  - /** A *webview when the load fails (request failed) +  */ the-(void) WebView: (UIWebView *) WebView didfailloadwitherror: (Nserror *) Error - { $NSLog (@"Didfailloadwitherror---"); the [Mbprogresshud Hidehud]; the } the  the  - @end

Print View:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.