UIWebView的简单学习
#import "ViewController.h" @interface ViewController ()<UIWebViewDelegate> { UIWebView *WebView; UIView *view; UIActivityIndicatorView *activityIndicator; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; WebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 400)]; [WebView setUserInteractionEnabled:NO];//是否支持交互 [WebView setBackgroundColor:[UIColor clearColor]]; [WebView setDelegate:self];//委托 [WebView setOpaque:NO];//使网页透明(Opaque为不透明的意思,这里为透明) //加载网页的方法 //1.创建并加载远程网页 NSString *path = @"http://www.baidu.com"; NSURL *url = [NSURL URLWithString:path]; [WebView loadRequest:[NSURLRequest requestWithURL:url]]; //创建UIActivityIndicatorView背底半透明View view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; [view setTag:103]; [view setBackgroundColor:[UIColor blackColor]]; [view setAlpha:0.8]; [self.view addSubview:view]; activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)]; [activityIndicator setCenter:view.center]; [activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite]; [view addSubview:activityIndicator]; [self.view addSubview:WebView]; } //开始加载数据 - (void)webViewDidStartLoad:(UIWebView *)webView { [activityIndicator startAnimating]; } //数据加载完 - (void)webViewDidFinishLoad:(UIWebView *)webView { [activityIndicator stopAnimating]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end