我有一個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