加载webView
来源:互联网 发布:淘宝单反四大黑店 编辑:程序博客网 时间:2024/05/29 07:00
1.创建UIWebView,为其配置request
UIWebView *webView = [[UIWebViewalloc]initWithFrame:CGRectMake(0,20,kScreenWidth,kScreenHeight)];
NSURLRequest *request = [[NSURLRequestalloc]initWithURL:[NSURLURLWithString:@"http://write.blog.csdn.net/postlist"]];
webView.delegate =self;
[self.viewaddSubview:webView];
[webView loadRequest:request];
2.在类中鉴定<UIWebVIewDelegate>,并设置代理为self
3.实现代理方法,用来检测 开始加载,加载完成,加载失败
- (void)webViewDidStartLoad:(UIWebView *)webView; //开始加载
- (void)webViewDidFinishLoad:(UIWebView *)webView; //加载完成
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullableNSError *)error; //加载失败
4.为了提升用户体验,由于网速的慢的原因,需要让用户知道此时是否正在加载
#pragma - mark webView的代理方法
- (void)webViewDidStartLoad:(UIWebView *)webView;{
//创建UIActivityIndicatorView背底半透明View
UIView *view = [[UIViewalloc]initWithFrame:self.view.frame];
[view setTag:108];
[view setBackgroundColor:[UIColorblackColor]];
[view setAlpha:0.5];
[self.viewaddSubview:view];
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorViewalloc]initWithFrame:CGRectMake(0.0f,0.0f,32.0f, 32.0f)];
[activityIndicator setCenter:view.center];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.tag =102;
[view addSubview:activityIndicator];
[activityIndicator startAnimating];
NSLog(@"webViewStartLoad");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView;{
UIActivityIndicatorView *activityIndicator = [self.viewviewWithTag:102];
[activityIndicator stopAnimating];
UIView *view = (UIView*)[self.viewviewWithTag:108];
[view removeFromSuperview];
NSLog(@"webViewDidFinishLoad");
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullableNSError *)error;{
UIActivityIndicatorView *activityIndicator = [self.viewviewWithTag:102];
[activityIndicator stopAnimating];
UIView *view = (UIView*)[self.viewviewWithTag:108];
[view removeFromSuperview];
NSLog(@"webViewdidFailLoad");
}
整理和参考容芳志的技术博客 http://blog.csdn.net/totogo2010/article/details/7686164
- 加载Webview
- 加载webView
- 加载webview
- 加载webView
- WebView加载
- WebView加载本地加载网络资源
- webview加载html
- iPad加载webView内容
- 监听webview 加载完成
- Android WebView 加载资源
- WebView加载本地HTML
- andriod webview加载地址
- WebView加载swf
- WebView加载本地资源
- webview进度条加载
- 判断webview加载完毕
- webview加载stringhtml
- webview 加载本地html
- Word Pattern
- Makefile missing separator. Stop.如何解决
- 参数数组
- 【Balanced Binary Tree】[NOI2004]郁闷的出纳员
- 运行时架构(Runtime Architecture)
- 加载webView
- 五角形图片
- JAVA9种基本数据类型的大小,以及他们的封装类
- Spring mvc中@RequestMapping 6个基本用法小结
- opencv对电脑摄像头采集和边缘检测
- 基本的线程机制(二)
- NO.2枚举法求水仙数
- JavaWeb:Tomcat server.xml配置示例
- Fibonacci Again模板