1
votes

I have a UIWebView and I load a local page that references a local CSS stylesheet. My app has the ability to let the user adjust the font size within the app, and so I want this to apply to the font size for local web pages that I show within the app too.

I know that I can inject javascript into a webview using stringByEvaluatingJavaScriptFromString.

How can I use Javascript to modify the font size for my HTML document?

1

1 Answers

1
votes

In the UIWebView delegate method webViewDidFinishLoad you can try this:

NSString *fontSize=@"14";
NSString *jsString = [[NSString alloc]      initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'",[fontSize intValue]];
[myWebview stringByEvaluatingJavaScriptFromString:jsString];

This adds JavaScript, as you mentioned, to adjust the font size to 14.