iOS,html使用互動相關

來源:互聯網
上載者:User

標籤:

1.UIWebView載入Html檔案

2.UIWebView的委託方法

UIWebView載入Html檔案

 //uiwebview載入網路頁面

    UIWebView *webView=[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    //自動對頁面進行縮放

    webView.scalesPageToFit=YES;

    //載入頁面內容,也可以載入本地檔案loginAlipay.html

    NSURL *url=[NSURL URLWithString:@"http://baidu.com"];

    NSURLRequest *request=[NSURLRequest requestWithURL:url];

    [webView loadRequest:request];

 

    [self.view addSubview:webView];

 

 

  //uiwebview載入本地html

    UIWebView *webView=[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    //自動對頁面進行縮放

    webView.scalesPageToFit=YES;

    //載入頁面內容,也可以載入本地檔案loginAlipay.html

   NSString *path=[[NSBundle mainBundle] pathForResource:@"loginAlipay"ofType:@"html"];

   NSURL *url=[NSURL fileURLWithPath:path];

  

    

    NSURLRequest *request=[NSURLRequest requestWithURL:url];

    [webView loadRequest:request];

 

    [self.view addSubview:webView];

 

UIWebView的委託方法

 //1.web視圖指示載入內容時通知。應該返回YES開始載入。導航提供的型別參數,是指請求的來源,可以是下列任何一個:  

//UIWebViewNavigationTypeLinkClicked     使用者觸擊了一個連結  

//UIWebViewNavigationTypeFormSubmitted   使用者提交了一個表單  

//UIWebViewNavigationTypeBackForward     使用者觸擊前進或返回按鈕  

//UIWebViewNavigationTypeReload          使用者觸擊重新載入的按鈕  

//UIWebViewNavigationTypeFormResubmitted 使用者重複提交表單  

//UIWebViewNavigationTypeOther           發生其它行為  

-(BOOL)webView:(UIWebView *)webView  shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;  

//2.開始載入的時候執行該方法。  

- (void)webViewDidStartLoad:(UIWebView *)webView;  

//3.載入完成的時候執行該方法。  

- (void)webViewDidFinishLoad:(UIWebView *)webView;  

//4.載入出錯的時候執行該方法。  

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;

iOS,html使用互動相關

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.