1. 程式人生 > >使網頁適應UIWebView的寬度

使網頁適應UIWebView的寬度

.get -s rom row ble 頁面 ati orm user

比較簡單的做法是:在- (void)webViewDidFinishLoad:這種方法中,改動JavaScript的值:

//UIWebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    /* 
      code
     */
    //改動頁面的meta的值
    if (SVPWebViewTypeActivity_Narrow == self.webViewType){
        NSString *meta = [NSString stringWithFormat:@"document.getElementsByName(\"viewport\")[0].content = \"width=%f, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"", webView.frame.size.width];
        [webView stringByEvaluatingJavaScriptFromString:meta];
    }
}




使網頁適應UIWebView的寬度