一、UIWebView可以加载和显示某个URL的网页,也可以显示基于HTML的本地网页或部分网页:
a. 加载URL
- WebView
= [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 400)]; - NSString
*path = @"http://www.baidu.com"; - NSURL
*url = [NSURL URLWithString:path]; - [WebView
loadRequest:[NSURLRequest requestWithURL:url]];
b. 加载 HTML
NSString *resPath = [bundle resourcePath];
NSString *filePath = [resPathstringByAppendingPathCom
[webView loadHTMLString:[NSStringstringWithContentsOfFile
二、使用网页加载指示,加载完成后再显示网页出来
- -
(void) webViewDidStartLoad:(UIWebView *)webView - {
-
//创建UIActivityIndicatorView背底半透明View -
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; -
[view setTag:108]; -
[view setBackgroundColor:[UIColor blackColor]]; -
[view setAlpha:0.5]; -
[self.view addSubview:view]; -
-
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)]; -
[activityIndicator setCenter:view.center]; -
[activityIndicator setActivityIndicatorView Style:UIActivityIndicatorViewS tyleWhite]; -
[view addSubview:activityIndicator]; -
-
[activityIndicator startAnimating]; - }
- -
(void) webViewDidFinishLoad:(UIWebView *)webView - {
-
[activityIndicator stopAnimating]; -
UIView *view = (UIView*)[self.view viewWithTag:108]; -
[view removeFromSuperview]; -
NSLog(@"webViewDidFinishLoad"); - }
三、UIWebView还可以通过 stringByEvaluatingJavaSc
NSString *theTitle=[webViewstringByEvaluatingJavaSc
NSString*currentURL = [webViewstringByEvaluatingJavaSc
NSString*js_result = [webViewstringByEvaluatingJavaSc
四、综合运用以上方法,还可以实现部分网页的显示,基本思路如下: