美文网首页
iOS webview html自适应

iOS webview html自适应

作者: 西江月 | 来源:发表于2017-03-30 16:37 被阅读148次

- (void)webViewDidFinishLoad:(UIWebView*)webView;//中添加

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

"myimg = document.images[i];"

"if(myimg.width > maxwidth){"

"oldwidth = myimg.width;"

"myimg.width = %f;"

"}"

"}"

"}\";"

"document.getElementsByTagName('head')[0].appendChild(script);";

js=[NSStringstringWithFormat:js,[UIScreenmainScreen].bounds.size.width,[UIScreenmainScreen].bounds.size.width-15];

[webViewstringByEvaluatingJavaScriptFromString:js];

[webViewstringByEvaluatingJavaScriptFromString:@"ResizeImages();"];

//设置字体大小

NSString*str =@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '90%'";

[webViewstringByEvaluatingJavaScriptFromString:str];

相关文章

网友评论

      本文标题:iOS webview html自适应

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