2011-04-25 179 views
0

我的webView加载完成后没有正确调整大小。我试过这段代码。UIWebView将不会调整大小以适应内容?

- (void)webViewDidFinishLoad:(UIWebView *)webview { 
    CGRect frame = webView.frame; 
    frame.size.height = 1; 
    frame.size.width = screenWidth; 
    webView.frame = frame; 
    CGSize fittingSize = [webView sizeThatFits:CGSizeZero]; 
    frame.size = fittingSize; 
    webView.frame = frame; 
    [bodyScroll setContentSize:CGSizeMake(screenWidth, webView.frame.origin.y + webView.frame.size.height+keyboardRectY+60)]; 

据incresing宽度超出屏幕宽度,因此我的内容在水平方向扩展超过此我不想视图尺寸。

改变

CGSize fittingSize = [webView sizeThatFits:CGSizeMake(screenWidht, 1)]; 

也导致了同样的情况。

我该如何摆脱这个? webview宽度应始终保持为屏幕宽度,并且只有高度应根据内容大小进行调整,以便webView能够适合整个内容。

由于提前

+0

看一看这个[SO后(http://stackoverflow.com/questions/922731/uiwebview-doesnt-seem-to-be-loading-the-page)搜索SO for autoresizingmask UIWebView – Rayfleck 2011-04-25 15:07:34

回答

0

当设置的frame大小,要覆盖您之前设置的宽度。这应该是:

... 
CGSize fittingSize = [webView sizeThatFits:CGSizeZero]; 
fittingSize.width = screenWidth; // Add this 
frame.size = fittingSize 
... 
+0

这设置框架确定,但我的文本仍然不会换行到screenWidth,但水平扩展超出screenWidth。为什么? – amateurcoder 2011-04-25 15:17:50

+4

我有同样的问题。当它真的不是正确的解决方案时,为什么选择这个答案作为正确答案? – aryaxt 2012-02-22 18:21:55

相关问题