views:

99

answers:

1

Hai Guys,

I got a problem while lodaing the htmlString into UIWebView, I have set the frame height of a webview in iphone is 265 always.

    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 41, 320, 265)];

Is there any property to get content height of a UIWebView.

If I got the content only one or two lines then it is looking odd below the two lines. How can I make it dynamic. Please suggest any solution.

Thank you, Madan Mohan.

A: 

try this:

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

in your webViewDidFinishLoad method.

MaxFish
I want to set the webView frame height if we know the height before loading. The string which is returning from given method is in piexls or what.
Madan Mohan
Sorry not to mention it. It's the height of the content in pixels. When you have that value you can set your webview frame height. I think there's no way to know the height before loading the page.
MaxFish
Sorry, Thanks for your response, But problem not solved.
Madan Mohan
The pixels I am getting is to large like 517, 233, if the content is only one line code
Madan Mohan
Does your problem is that you don't want to display the webview before knowing the exact size?
MaxFish
Even after loading i want to change the webview frame height, How can I
Madan Mohan
If you are loading page from a string you have to be sure it is a correct HTML document. This works:NSString * html = @"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"it\" dir=\"ltr\"><html><head><title>aaaa</title></head><body>Test!</body></html>";
MaxFish