The use of UIWebView in IOS _ios

Source: Internet
Author: User

First, initialization and three kinds of loading methods

UIWebView inherits and UIView, so its initialization method, like the general view, is initialized by Alloc and Init with three different ways of loading data:

First type:

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

This is the most commonly used way to load Web pages, through a Web page URL to load, this URL can be remote or local, such as I loaded Baidu's homepage:

UIWebView * view = [[UIWebView alloc]initwithframe:self.view.frame];
[View loadrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:@ "http://www.baidu.com"]];
[Self.view Addsubview:view];

will get the following effect:

The second type:

-(void) loadhtmlstring: (NSString *) string BaseURL: (Nsurl *) BaseURL;

This method needs to read the httml file as a string, where BaseURL is a path that we set ourselves to look for material such as the picture referenced in the HTML file.

The third type:

-(void) LoadData: (NSData *) data mimetype: (NSString *) mimetype textencodingname: (NSString *) Textencodingname BaseURL: ( Nsurl *) BaseURL;

This method uses less, but also more free, where data is file data, MimeType is file type, Textencodingname is the encoding type, BaseURL is the material resource path.

Second, some commonly used properties and variables

@property (nonatomic, assign) ID <UIWebViewDelegate> delegate;

Set up a WebView agent

@property (Nonatomic, ReadOnly, retain) Uiscrollview *scrollview;

Built in ScrollView

@property (Nonatomic, ReadOnly, retain) Nsurlrequest *request;

URL Request

-(void) reload;

Reload data

-(void) stoploading;

Stop loading Data

-(void) goBack;

Go back to the previous level

-(void) GoForward;

Jump Next Level

@property (nonatomic, ReadOnly, getter=cangoback) BOOL cangoback;

Gets whether to return to the previous level

@property (nonatomic, ReadOnly, Getter=cangoforward) BOOL CanGoForward;

Get whether to jump to the next level

@property (nonatomic, ReadOnly, getter=isloading) BOOL loading;

Gets whether data is being loaded

-(NSString *) stringbyevaluatingjavascriptfromstring: (NSString *) script;

Manipulating Web data through JavaScript

@property (nonatomic) BOOL scalespagetofit;

Set whether to scale to fit screen size

@property (nonatomic) uidatadetectortypes datadetectortypes Ns_available_ios (3_0);

Set some data into a link form, this enumeration can be set such as phone number, address, mailbox, etc. into a link

@property (nonatomic) BOOL allowsinlinemediaplayback Ns_available_ios (4_0);

Set whether to play the video using the inline player

@property (nonatomic) BOOL mediaplaybackrequiresuseraction Ns_available_ios (4_0);

Set whether the video will play automatically

@property (nonatomic) BOOL mediaplaybackallowsairplay Ns_available_ios (5_0);

Set whether audio playback supports Ari play feature

@property (nonatomic) BOOL suppressesincrementalrendering Ns_available_ios (6_0);

Set whether to load data as memory after rendering the interface

@property (nonatomic) BOOL keyboarddisplayrequiresuseraction Ns_available_ios (6_0);

Set User interaction Mode

Some new features in the IOS7

The following properties are available after iOS7, and they allow you to set up a more interesting web experience

@property (nonatomic) uiwebpaginationmode paginationmode Ns_available_ios (7_0);

This property is used to set a pattern that, when the size of a Web page exceeds view, shows the page's effect, as shown in the following enumeration:

typedef ns_enum (Nsinteger, Uiwebpaginationmode) {
uiwebpaginationmodeunpaginated,//does not use paging effect
uiwebpaginationmodelefttoright,//the page out of part of the page, paging from left to right uiwebpaginationmodetoptobottom,//the page out of
part of the page and from top to bottom
uiwebpaginationmodebottomtotop,//pages out of section and page up
uiwebpaginationmoderighttoleft//the page out of part of the page and pages from right to left
.

@property (nonatomic) cgfloat pagelength Ns_available_ios (7_0);

Set the length of each page

@property (nonatomic) cgfloat gapbetweenpages Ns_available_ios (7_0);

Set spacing for each page

@property (nonatomic, readonly) Nsuinteger PageCount Ns_available_ios (7_0);

Get pages

Iv. methods in the WebView protocol

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

The method that is invoked when the content is loaded, and the setting that is loaded by the return value

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

method to call when starting load

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

method to call at end of load

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

method to call when load fails

Related Article

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.