美文网首页
WKWebView自适应里面图片的大小

WKWebView自适应里面图片的大小

作者: 黄花菜先生 | 来源:发表于2018-01-17 14:49 被阅读50次
    -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    
        NSString *js=@"var script = document.createElement('script');"
        "script.type = 'text/javascript';"
        "script.text = \"function ResizeImages() { "
        "var myimg,oldwidth;"
        "var maxwidth = %f;"
        "for(i=0;i <document.images.length;i++){"
        "myimg = document.images[i];"
        "if(myimg.width > maxwidth){"
        "oldwidth = myimg.width;"
        "myimg.width = %f;"
        "}"
        "}"
        "}\";"
        "document.getElementsByTagName('head')[0].appendChild(script);";
        
        js = [NSString stringWithFormat:js,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.width-15];
        
        [webView evaluateJavaScript:js completionHandler:nil];
        
        [webView evaluateJavaScript:@"ResizeImages();"completionHandler:nil];
    
    }

    相关文章

      网友评论

          本文标题:WKWebView自适应里面图片的大小

          本文链接:https://www.haomeiwen.com/subject/yeecuxtx.html