How to de- and increase the font size with WKWebView?

混江龙づ霸主 提交于 2019-12-09 16:11:18

问题


In Safari you can increase and decrease the font size. How can I achieve the same effect with WKWebView?


回答1:


The codes suggested by Inna used to work but stopped working from iOS10.3. I did some research and found that we need to make a slight change to it, just changing "%%" to a single "%".

So JS code should be:

let js = "document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust='\(fontSize)%'"

I got this info from Apple Developer forum. https://forums.developer.apple.com/thread/51079




回答2:


Assume that you have fontUpdatedHeight integer which gives you the exact fontsize.

Just create string like that:

NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%lu%%'",(unsigned long)fontUpdatedHeight];

And execute the NSString

[self.WKWebView stringByEvaluatingJavaScriptFromString:jsString];


来源:https://stackoverflow.com/questions/34130319/how-to-de-and-increase-the-font-size-with-wkwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!