Reputation: 107
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.
Upvotes: 1
Views: 808
Reputation: 5128
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 :)
Upvotes: 1
Reputation: 20021
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
Upvotes: 0