本文主要是介绍UIWebView加载Loading...,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
ViewController.h文件
#import <UIKit/UIKit.h>
@interface ViewController :UIViewController<UIWebViewDelegate>//加载声明UIWebviewDelegate协议
{
UIWebView *webView;
UIActivityIndicatorView *activityIndicator;
}
ViewController.m文件
//加载网页
- (void)viewDidLoad
{
[superviewDidLoad];
webView = [[UIWebViewalloc] initWithFrame:CGRectMake(0,0, 320,480)];
[webViewsetDelegate:self];
NSURLRequest *request =[NSURLRequestrequestWithURL:[NSURLURLWithString:@"http://www.zqksk.com/ios/xzqcf/index.html"]];
[self.viewaddSubview: webView];
[webViewloadRequest:request];
}
- (void) webViewDidStartLoad:(UIWebView *)webView
{
//创建UIActivityIndicatorView背底半透明View
UIView *view = [[UIViewalloc] initWithFrame:CGRectMake(0,0, 320, 480)];
[viewsetTag:108];
[view setBackgroundColor:[UIColorblackColor]];
[viewsetAlpha:0.5];
[self.viewaddSubview:view];
activityIndicator = [[UIActivityIndicatorViewalloc] initWithFrame:CGRectMake(0.0f,0.0f, 32.0f, 32.0f)];
[activityIndicatorsetCenter:view.center];
[activityIndicatorsetActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[view addSubview:activityIndicator];
[activityIndicatorstartAnimating];
NSLog(@"webViewDidStartLoad");
}
/////数据加载完
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
[activityIndicatorstopAnimating];
UIView *view = (UIView*)[self.viewviewWithTag:108];
[view removeFromSuperview];
NSLog(@"webViewDidFinishLoad");
}
- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[activityIndicatorstopAnimating];
UIView *view = (UIView*)[self.viewviewWithTag:108];
[view removeFromSuperview];
NSLog(@"didFailLoadWithError:%@", error);
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
if (myAlert==nil){
myAlert = [[UIAlertViewalloc] initWithTitle:nil
message: @"正在玩命加载当中..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
UIActivityIndicatorView *activityView = [[UIActivityIndicatorViewalloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];//加载时指示器的颜色
activityView.frame =CGRectMake(120.f,48.0f, 37.0f,37.0f);//设置对象的位置,大小是固定不变的。WhiteLarge为37 * 37,White为20 * 20
activityView.color = [UIColor redColor];//指示器的颜色
[myAlertaddSubview:activityView];//将对像加入到VIEW
[activityViewrelease];要记得将对象release
[activityViewstartAnimating];//开启动画(指示器)
[myAlertshow];
}
_reloading = YES;
}
////数据加载完
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[myAlertdismissWithClickedButtonIndex:0animated:YES];
_reloading = NO;
[_refreshHeaderViewegoRefreshScrollViewDataSourceDidFinishedLoading:self.uiWebView.scrollView];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(@"load page error:%@", [errordescription]);
_reloading = NO;
[_refreshHeaderViewegoRefreshScrollViewDataSourceDidFinishedLoading:self.uiWebView.scrollView];
}
转:
http://justcoding.iteye.com/blog/1535070
http://lijinfengjava.iteye.com/blog/1508377
http://blog.sina.com.cn/s/blog_7fa6b06f010121mr.html
这篇关于UIWebView加载Loading...的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!