第一、初始化

 

1._webView=[[UIWebView alloc] initWithFrame:CGRectOffset(self.view.bounds, 020)];
2._webView.delegate=self;
3.NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
4.[_webView loadRequest:request];
5.[self.view addSubview:_webView];


第二、三个代理方法

 

 

01.#pragma webview delegate
02.- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
03.{
04.return true;
05.}
06.- (void)webViewDidStartLoad:(UIWebView *)webView
07.{
08.UIView *view = [[UIView alloc] initWithFrame:CGRectMake(00320480)];
09.[view setTag:108];
10.[view setBackgroundColor:[UIColor blackColor]];
11.[view setAlpha:0.5];
12.[self.view addSubview:view];
13. 
14.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f,32.0f)];
15.[activityIndicator setCenter:view.center];
16.[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
17.[view addSubview:activityIndicator];
18. 
19.[activityIndicator startAnimating];}
20.- (void)webViewDidFinishLoad:(UIWebView *)webView
21.{
22.[activityIndicator stopAnimating];
23.UIView *view=[self.view viewWithTag:108];
24.[view removeFromSuperview];
25.}
26.- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
27.{
28.NSLog(@"HELLO");
29.}

 

arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()