WKWebView適応中の画像のサイズ

971 ワード

-(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  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];

}