OC开发资料收集区

ios webView的使用

2017-06-01  本文已影响48人  oc123

本文简述webView加载一个网页,代码如下:

//遵循代理
<UIWebViewDelegate>
//设置代理
_webView.delegate = self;
#pragma mark 开始加载数据
- (void)startLoad
{
    NSURL* url = [NSURL URLWithString:urlStr];
    NSURLRequest* request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
}
#pragma mark webViewDelegate
// 开始加载
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
}

// 结束加载
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

// 开始加载失败
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
上一篇下一篇

猜你喜欢

热点阅读