我有一个UIWebview我想更改字体大小。 要做到这一点,我只是用javascript:更改字体大小时调整UIWebview的框架大小
NSString *jsString = [NSString stringWithFormat:@"document.body.style.webkitTextSizeAdjust= '%d%%'",50];
[t_webview stringByEvaluatingJavaScriptFromString:jsString];
的问题是,当我设置字体大小为50%,存在的UIWebView的内容下面一大空白区域。
我想我的web视图调整到通过运行以下JS贴合实际的内容大小的高度,但它总是返回100%文本的高度,而不是50%,实际之一:
NSLog(@"font size: %i%%",theHeightIWant);
NSString* t_height = [t_webview stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"];
NSLog(@"height before: %@",t_height);
NSString *jsString = [NSString stringWithFormat:@"document.body.style.webkitTextSizeAdjust= '%d%%'",theHeightIWant];
[t_webview stringByEvaluatingJavaScriptFromString:jsString];
t_height = [t_webview stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"];
NSLog(@"height after: %@",t_height);
---- ------日志
font size: 95%
height before: 932
height after: 932
font size: 90%
height before: 932
height after: 932
font size: 85%
height before: 932
height after: 932
我还试图用document.documentElement.scrollHeight代替document.body.offsetHeight但这也不管用。
任何人都可以帮助我吗?谢谢。
编辑:这是我如何加载HTML的网页视图:
NSString* t_html = [NSString stringWithFormat:@"<html><body>%@</body></html>",t_htmlPharmaco];
[webview loadHTMLString:t_html baseURL:[[NSBundle mainBundle] bundleURL]];
该错误消失,但我不知道为什么.....要继续 – Imotep
您是否得到任何解决方案? ?我面临着同样的问题@Imotep –
从我记得我没有,并没有别的选择,只留下内容下面的空白空间。但是从现在开始已经超过3年了,我可能会错,而且我不能再访问源代码来确认。 – Imotep