WebView的基本使用

來源:互聯網
上載者:User

標籤:缺點   檢測   監聽   uiwebview   uid   代理   ber   types   tsm   

1 概念性知識    01 webView是有缺點的,會導致記憶體泄露,而且這個問題是它系統本身的問題。    02 手機上面的safai其實就是用webView來實現的    03 現在的開發並不完全是原生的開發,而更加傾向於原生+Html5的方式 04 webView是OC代碼和html代碼之間進行互動的橋樑2 代碼相關/*A*網頁操控相關方法**/ [self.webView goBack]; 回退 [self.webView goForward]; 前進 [self.webView reload]; 重新整理 //設定是否能夠前進和回退 self.goBackBtn.enabled = webView.canGoBack; self.fowardBtn.enabled = webView.canGoForward;/*B*常用的屬性設定**/ self.webView.scalesPageToFit = YES; 設定網頁自動適應 self.webView.dataDetectorTypes = UIDataDetectorTypeAll; 設定檢測網頁中的格式類型,all表示檢測所有類型包括超連結、電話號碼、地址等。 self.webView.scrollView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0);/*C*相關代理方法**/ //每當將載入請求的時候調用該方法,返回YES 表示載入該請求,返回NO 表示不載入該請求 //可以在該方法中攔截請求 -(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/*D*其它知識點-載入本地資源**/ NSURL *url = [[NSBundle mainBundle] URLForResource:@"text.html" withExtension:nil]; [self.webView loadRequest:[NSURLRequest requestWithURL:url]];

WebView的基本使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.