The original address: https://my.oschina.net/u/2340880/blog/469916

UIWebView inherits from UIView, therefore, its initialization method is the same as the general view, through alloc and init initialization, it load data in three ways:

  • (void)loadRequest:(NSURLRequest *)request; This is the most common way to load a web page, through a web URL to load, the URL can be remote or local, for example, I load baidu’s home page:
    UIWebView * view = [[UIWebView alloc]initWithFrame:self.view.frame];    [view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]];    [self.view addSubview:view];
Copy the code

The following results should be obtained:

  • (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL; This method requires reading HTTML files as strings, where baseURL is a path we set ourselves to find materials such as images referenced in HTML files.

The third:

  • (void)loadData:(NSData *)data MIMEType:(NSString )MIMEType textEncodingName:(NSString)textEncodingName baseURL:(NSURL *)baseURL; This approach is less used, but also more liberal, where Data is the file data, MIMEType is the file type, textEncodingName is the encoding type, and baseURL is the material resource path. Some common attributes and variables@property(nonatomic, assign) id delegate; Set the webView proxy@property(nonatomic, readonly, retain) UIScrollView *scrollView; The built-in scrollView@property(nonatomic, readonly, retain) NSURLRequest *request; The URL request
  • (void)reload; Reload data
  • (void)stopLoading; Stop loading data
  • (void)goBack; Return to the previous level
  • (void)goForward; @property (nonatomic, readOnly, getter=canGoBack) BOOL canGoBack; @property (nonatomic, readOnly, getter=canGoForward) BOOL canGoForward; @property (nonatomic, readOnly, getter=isLoading) BOOL loading; Gets whether data is being loaded
  • (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script; @Property (Nonatomic) BOOL scalesPageToFit; @Property (nonatomic) UIDataDetectorTypes dataDetectorTypes NS_AVAILABLE_IOS(3_0); Set up some form of data into a link, the enumeration can be set such as phone number, address, email, etc into link @ property (nonatomic) BOOL allowsInlineMediaPlayback NS_AVAILABLE_IOS _0 (4); Set whether to use inline players play video @ property (nonatomic) BOOL mediaPlaybackRequiresUserAction NS_AVAILABLE_IOS _0 (4); Sets whether video automatically play @ property (nonatomic) BOOL mediaPlaybackAllowsAirPlay NS_AVAILABLE_IOS _0 (5); Set the audio playback support ari play function @ property (nonatomic) BOOL suppressesIncrementalRendering NS_AVAILABLE_IOS _0 (6); Set whether to load data such as memory after rendering interface @ property (nonatomic) BOOL keyboardDisplayRequiresUserAction NS_AVAILABLE_IOS _0 (6); Set user interaction mode 3, some new features in iOS7 The following properties are not available since iOS7, @property (nonatomic) UIWebPaginationMode paginationMode NS_AVAILABLE_IOS(7_0); This property sets the mode for displaying a page as a flip when the size of the page exceeds the view. Enumerations are as follows: typedef NS_ENUM(NSInteger, UIWebPaginationMode) {UIWebPaginationModeUnpaginated, / / no use flip effect UIWebPaginationModeLeftToRight, / / the web page beyond the part of the page, From left to right to flip UIWebPaginationModeTopToBottom, / / will be web pages, excess part from the top down to flip UIWebPaginationModeBottomToTop, / / will be web pages, excess part From the bottom up paging up UIWebPaginationModeRightToLeft / / will be web pages, excess part from right to left to flip};

@property (nonatomic) CGFloat pageLength NS_AVAILABLE_IOS(7_0); Set the length of each page @Property (nonatomic) CGFloat gapBetweenPages NS_AVAILABLE_IOS(7_0); @property (nonatomic, readonly) NSUInteger pageCount NS_AVAILABLE_IOS(7_0); Get the number of pages 4

  • (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; Method called when content is ready to load, setting whether or not to load by returning a value
  • (void)webViewDidStartLoad:(UIWebView *)webView; Method called when loading begins
  • (void)webViewDidFinishLoad:(UIWebView *)webView; Method called when loading ends
  • (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error; Method called when loading fails