Is there a way to resize font automatically in a UIWebView so it will look best on screen? Something that will try to set the font size to be in the ideal size for viewing (assuming resizing the text will just wrap the text and not corrupt the whole page).
I had the same problem, this workaround worked for me:
-(void)webViewDidFinishLoad:(UIWebView *)webView{
[webView scalesPageToFit];
float scale = 130000/webView.scrollView.frame.size.width;
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%f%%'", scale];
[webView stringByEvaluatingJavaScriptFromString:jsString];
}
I have several UIWebViews of different widths. I want to keep zooming enabled, so scalePageToFit is switched on, which results in tiny text for the UIWebviews of smaller width and large font for UIWebviews of a larger width. To standardise the font size, calculate the scale by dividing some factor (you'll have to adjust this yourself, 130000 worked for me with CSS font size 10pt) by the webview width.
As far as I can tell it's not related to zoomFactor, which is always 1.0. I haven't checked if the fonts are exactly the same size (visually) across the UIWebViews, but good enough for me not to be able to tell.
You should set the scalesPageToFit
property to YES
You can read the documentation Here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With