The first of these methods
-(void) Webviewdidfinishload: (uiwebview *) WebView
{
cgfloat Webviewheight=[webview. ScrollViewcontentsize]. height;
cgrect newframe = WebView. frame;
Newframe. size. height = webviewheight;
WebView. frame = newframe;
_webtablewview. contentsize =cgsizemake(newframe. Size. height + + kwidth -+);
}
//2. Execute the JS statement to get the DOM height of the HTML document directly
-(void) webviewdidfinishload: ( UIWebView *) webview{
Cgfloatwebviewheight =[[webviewstringbyevaluatingjavascriptfromstring:@ "Document.body.offsetHeight"] Floatvalue];
CGFloat webviewheight= [[webviewstringbyevaluatingjavascriptfromstring:@ "Document.body.scrollHeight"] Floatvalue];
Cgrectnewframe = Webview.frame;
Newframe.size.height= Webviewheight;
Webview.frame= Newframe;
}
// Method 3. Set the height of the UIWebView to a minimum, and then use Sizethatfits to return exactly the right size
-(void) Webviewdidfinishload: (uiwebview*) webvie{
cgsize actualsize = [WebView sizethatfits:Cgsizezero];
cgrect newframe = WebView. frame;
Newframe. size. height = actualsize. height;
WebView. frame = newframe;
}
Method 4. Traverse the WebView sub-view to get the Uiwebdocumentview height i.e. the actual height
-(void) Webviewdidfinishload: (uiwebview *) webview{
cgfloat webviewheight = 0.0f;
if ([WebView. subviews Count] > 0)
{
UIView *scrollerview = WebView. subviews [0];
if ([Scrollerview. subviews Count] >
0)
{
UIView *webdocview = Scrollerview. subviews. Lastobject;
if ([Webdocviewiskindofclass: [nsclassfromstring(@ "Uiwebdocume Ntview ")class])
{
Webviewheight = Webdocview. frame. size. height; // get the height of a document
WebView. frame=webdocview. frame;
// update The height of the UIWebView
}
}
}
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS WebView Adaptive Real content height 4 ways