• 热门专题

UIWebView使用

作者:  发布日期:2014-04-08 19:26:12
Tag标签:
  • 第一、初始化

        _webView=[[UIWebView alloc] initWithFrame:CGRectOffset(self.view.bounds, 0, 20)];
        _webView.delegate=self;
        NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
        [_webView loadRequest:request];
        [self.view addSubview:_webView];
    

    第二、三个代理方法

    #pragma webview delegate
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    {
        return true;
    }
    - (void)webViewDidStartLoad:(UIWebView *)webView
    {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        [view setTag:108];
        [view setBackgroundColor:[UIColor blackColor]];
        [view setAlpha:0.5];
        [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];
        
        [activityIndicator startAnimating];}
    - (void)webViewDidFinishLoad:(UIWebView *)webView
    {
        [activityIndicator stopAnimating];
        UIView *view=[self.view viewWithTag:108];
        [view removeFromSuperview];
    }
    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
    {
        NSLog(@"HELLO");
    }
    


延伸阅读:

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规