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




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值