#import<UIKit/UIKit.h>
@interface WebViewController : UIViewController
@end
#import "WebViewController.h"
@interface WebViewController ()<UIWebViewDelegate>
{
UIWebView *webView;
UIActivityIndicatorView *activity;
}
@end
@implementation WebViewController
- (void)viewDidLoad {
[self _creatImageView];
}
- (void)_creatImageView{
// NSLog(@"%@",_urlStr);
webView = [[UIWebView alloc]initWithFrame:CGRectMake(0,0, self.view.bounds.size.width, self.view.bounds.size.height)];
webView.backgroundColor = [UIColor whiteColor];
NSString *webStr = @"https://qr.alipay.com/apx08944gtboitcgqa8vjf8";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:webStr]];
[self.view addSubview:webView];
webView.delegate = self;
[webView loadRequest:request];
}
//网页开始加载的时候调用
- (void )webViewDidStartLoad:(UIWebView *)webView{
NSLog(@"webViewDidStartLoad");
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[view setTag:108];
[view setBackgroundColor:[UIColor blackColor]];
[view setAlpha:0.5];
[self.view addSubview:view];
activity = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 50.0f, 50.0f)];
[activity setCenter:view.center];
[activity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
[view addSubview:activity];
[activity startAnimating];
}
//网页加载完成的时候调用
- (void )webViewDidFinishLoad:(UIWebView *)webView {
[activity stopAnimating];
UIView *view = (UIView *)[self.view viewWithTag:108];
[view removeFromSuperview];
NSLog(@"webViewDidFinishLoad");
}
//网页加载错误的时候调用
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[activity stopAnimating];
UIView *view = (UIView *)[self.view viewWithTag:108];
[view removeFromSuperview];
NSLog(@"didFailLoadWithError:%@",error);
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请检查网络是否连接正确" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
@end