iOS --- UIWebView和WKWebView 改变html图片尺寸及字体大小

一、UIWebView 中的 方法可以直接加载

stringByEvaluatingJavaScriptFromString:

- (void)webViewDidFinishLoad:(UIWebView *)webView{
[webView stringByEvaluatingJavaScriptFromString:
@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.text = \"function ResizeImages() { "
"var myimg,oldwidth;"
"var maxwidth = 1000.0;" // UIWebView中显示的图片宽度
"for(i= 1;i 
二、WKWebVIew 也就是方法不一样

[evaluateJavaScript:completionHandler: ]方法,JS部分和上面的一样。

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
       [ webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '300%'" completionHandler:nil];
    [ webView evaluateJavaScript:@"var script = document.createElement('script');"
     "script.type = 'text/javascript';"
     "script.text = \"function ResizeImages() { "
     "var myimg,oldwidth;"
     "var maxwidth = 1000.0;" // UIWebView中显示的图片宽度
     "for(i=1;i 

你可能感兴趣的:(iOS --- UIWebView和WKWebView 改变html图片尺寸及字体大小)