Jonas
Jonas

Reputation: 1234

iOS UIWebView with changing content size

I have a UIWebView which i've set the height of the WebView to

[[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];

This works fine but on my webpage I have a menu which is expandable, so when the webpage is changing it's height the WebView doesn't increase/decrease it's size.

Any tips how I can make my UIWebView change height dynamically when the webpage is changing its size?

I would very much like to keep the UIWebView's size = webpage so I never have to scroll in the WebView.

Upvotes: 3

Views: 12406

Answers (3)

thorb65
thorb65

Reputation: 2716

Try setting the contenSize of its scrollview:

detailsWebView.scrollView.contentSize = CGSizeMake(detailsWebView.scrollView.contentSize.width,[[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue]);

Upvotes: 2

the1pawan
the1pawan

Reputation: 1204

you can set sizeToFit property and again set Frame of UIWebView in webViewDidFinishLoad

- (void)webViewDidFinishLoad:(UIWebView *)webView{
       [detailsWebView sizeToFit];
       [detailsWebView setFrame:CGRectMake(detailsWebView.frame.origin.x, detailsWebView.frame.origin.y, 300.0, detailsWebView.frame.size.height)];

}

Upvotes: 2

samir
samir

Reputation: 4551

Use the UIWebView property scalesPageToFit = YES;

Upvotes: 0

Related Questions