开发者

UIWebView won't resize to fit content?

My webView is not resizing properly after it finished loading. I have tried this code.

- (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)];

It is incresing the width beyond the screenWidth and hence my content horizontally expands beyond the view size which I don't want.

changing

CGSize fittingSize = [webView 开发者_如何学GosizeThatFits:CGSizeMake(screenWidht, 1)];

also leads to the same situation.

How can I get rid of this? The webview width should always remain as screenwidth and only it's height should adjust based on the content size so that the webView just about fits the whole content.

Thanks in Advance


When setting the size of frame, you are overwriting the width you set previously. This should it:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜