First, initialize and three kinds of loading methods
UIWebView inherits from the UIView, so its initialization method, like the normal view, is initialized by Alloc and Init with three ways of loading the data:
The first type:
-(void) Loadrequest: (nsurlrequest *) request;
This is the most common way to load a webpage, through a Web page URL to load, this URL can be remote or local, such as I load Baidu's homepage:
?
| 123 |
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 we set ourselves to look for footage such as images referenced in an 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 freely, where data is the file, MimeType is the file type, Textencodingname is the encoding type, and BaseURL is the asset path.
Ii. some common properties and variables
@property (nonatomic, assign) ID <UIWebViewDelegate> delegate;
Set up a proxy for WebView
@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;
Back to upper level
-(void) GoForward;
Jump to the next level
@property (nonatomic, ReadOnly, getter=cangoback) BOOL cangoback;
Gets whether to return to the previous level
@property (nonatomic, ReadOnly, Getter=cangoforward) BOOL CanGoForward;
Gets whether to jump to the next level
@property (nonatomic, ReadOnly, getter=isloading) BOOL loading;
Gets whether the data is being loaded
-(NSString *) stringbyevaluatingjavascriptfromstring: (nsstring*) script;
Manipulating Web data through JavaScript
@property (nonatomic) BOOL scalespagetofit;
Set whether to scale to fit the screen size
@property (nonatomic) uidatadetectortypes datadetectortypes Ns_available_ios (3_0);
Set some data into link form, this enumeration can be set such as phone number, address, mailbox and so on into a link
@property (nonatomic) BOOL allowsinlinemediaplayback Ns_available_ios (4_0);
Set whether to play a video using an inline player
@property (nonatomic) BOOL mediaplaybackrequiresuseraction Ns_available_ios (4_0);
Set whether video plays automatically
@property (nonatomic) BOOL mediaplaybackallowsairplay Ns_available_ios (5_0);
Set whether audio playback supports the ARI Play feature
@property (nonatomic) BOOL suppressesincrementalrendering Ns_available_ios (6_0);
Sets whether to load data such as in-memory render interface
@property (nonatomic) BOOL keyboarddisplayrequiresuseraction Ns_available_ios (6_0);
Set User interaction Mode
Iii. some new features in iOS7
The following properties are available after iOS7, through which they can 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 page exceeds the view, displays the page as the effect of page flipping, enumerated as follows:
?
| 1234567 |
typedefNS_ENUM(NSInteger, UIWebPaginationMode) { UIWebPaginationModeUnpaginated,//不使用翻页效果 UIWebPaginationModeLeftToRight,//将网页超出部分分页,从左向右进行翻页 UIWebPaginationModeTopToBottom,//将网页超出部分分页,从上向下进行翻页 UIWebPaginationModeBottomToTop,//将网页超出部分分页,从下向上进行翻页 UIWebPaginationModeRightToLeft//将网页超出部分分页,从右向左进行翻页}; |
@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 the spacing for each page
@property (nonatomic, readonly) Nsuinteger PageCount Ns_available_ios (7_0);
Get the number of pages
Iv. methods in the WebView protocol
-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) Navigationtype;
The method that is called when the content is ready to be loaded, and the settings that are loaded by the return value
-(void) Webviewdidstartload: (UIWebView *) WebView;
method to invoke when loading starts
-(void) Webviewdidfinishload: (UIWebView *) WebView;
Method called when the load is ended
-(void) WebView: (UIWebView *) WebView didfailloadwitherror: (nserror *) error;
Methods that are called when a load fails
Common properties and methods for IOS WebView