WebView的基本使用
1 概念性知识
01 webView是有缺点的,会导致内存泄露,而且这个问题是它系统本身的问题。
02 手机上面的safai其实就是用webView来实现的
03 现在的开发并不完全是原生的开发,而更加倾向于原生+Html5的方式
04 webView是OC代码和html代码之间进行交互的桥梁
2 代码相关
[self.webView goBack]; 回退
[self.webView goForward]; 前进
[self.webView reload]; 刷新
self.goBackBtn.enabled = webView.canGoBack;
self.fowardBtn.enabled = webView.canGoForward;
self.webView.scalesPageToFit = YES; 设置网页自动适应
self.webView.dataDetectorTypes = UIDataDetectorTypeAll; 设置检测网页中的格式类型,all表示检测所有类型包括超链接、电话号码、地址等。
self.webView.scrollView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0);
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return ![request.URL.absoluteString containsString:@"dushu"];
}
-(void)webViewDidStartLoad:(UIWebView *)webView
-(void)webViewDidFinishLoad:(UIWebView *)webView
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
NSURL *url = [[NSBundle mainBundle] URLForResource:@"text.html" withExtension:nil];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];