1

We are developing an application that shows list of "tips" where the description of "tip" is in HTML format and may contains "" tags.

We are using WebView to show the description and would like to expand the height (scale up the height) of WebView based on the content of the "tip" description.

Please let us know if any possibility.

Thanks a lot.

Umang
  • 107
  • 7

2 Answers2

1

In webViewDidFinishLoad delegate method,get the height from the html body.

- (void)webViewDidFinishLoad:(UIWebView *)webView
{

float newHeight= [[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];

OR

if you want to retrive height of specific div tag with id(example:<div id='tips' style='background: red'>This is just an example test.</div>

//then,do this

NSString *output = [webview stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"tips\").offsetHeight;"];

//Convert it to float

//Then set new height like this.

[webview setBounds:CGRectMake(oldBounds.x, oldBounds.y, oldBounds.width, newHeight)];

}

Happy Coding :)

Master Stroke
  • 5,108
  • 2
  • 26
  • 57
0

Well the [webView setFrame:Frame] method can be used for the purpose of setting height programmatically .The problem is how to get the height of the content of HTML.If you can get the height of the content then it is a workable option

Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
  • Yes, we are doing the same but the issue is as you have described that we don't know the height of HTML content. so, we are looking for something like wrap-content in android. – Umang Feb 16 '13 at 07:43
  • @Umang check this Question http://stackoverflow.com/questions/3837214/how-to-get-the-content-height-of-a-uiwebview-in-iphone-sdk-objective-c – Lithu T.V Feb 16 '13 at 07:46