//初始化webview
webview =[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
webview.delegate =self;
NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
[webview loadRequest:request];
[self.view addSubview:webview];
//webview 代理方法
//开始加载时调用
- (void)webViewDidStartLoad:(UIWebView *)webView;
//加载完毕后调用
- (void)webViewDidFinishLoad:(UIWebView *)webView;
//加载失败时调用
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error;
//等待加载时的圈
- (void)webViewDidStartLoad:(UIWebView *)webView
{
UIView *view =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
view.tag =108;
view.backgroundColor =[UIColor blackColor];
view.alpha =0.5;
[self.view addSubview:view];
activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 32, 32)];
activityIndicator.center =view.center;
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[view addSubview:activityIndicator];
[activityIndicator startAnimating];
}
//加载完毕或者失败时去掉圈
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[activityIndicator stopAnimating];
UIView *view =(UIView *)[self.view viewWithTag:108];
[view removeFromSuperview];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error
{
[activityIndicator stopAnimating];
UIView *view =(UIView *)[self.view viewWithTag:108];
[view removeFromSuperview];
}