//第一种方法
- (void)webviewdidfinishload:(uiwebview *)webview { cgfloat webviewheight=[webview.scrollview contentsize].height; cgrect newframe = webview.frame; newframe.size.height = webviewheight; webview.frame = newframe; _webtablewview.contentsize = cgsizemake(320, newframe.size.height + 64 + kwidth - 100); }
//2.执行js语句 直接获取html文档的dom高度
- (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; }
//方法3.先将uiwebview的高度设为最小,然后再使用sizethatfits就会返回刚好合适的大小
-(void)webviewdidfinishload:(uiwebview*)webvie{ cgsize actualsize = [webview sizethatfits:cgsizezero]; cgrect newframe = webview.frame; newframe.size.height = actualsize.height; webview.frame = newframe; }
//方法4.遍历webview子视图 获取uiwebdocumentview高度即实际高度
-(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 ([webdocview iskindofclass:[nsclassfromstring(@uiwebdocumentview)class]]) { webviewheight = webdocview.frame.size.height;//获取文档的高度 webview.frame=webdocview.frame; //更新uiwebview 的高度 } } } }
以上所述是小编给大家介绍的ios webview自适应实际内容高度的4种方法详解,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
纵横字谜的答案 Crossword Answers, ACM/ICPC World Finals 1994, UVa232
HDU - 5880 Family View (AC自动机修改母串)
iOS14Beta3续航怎么样 iOS14Beta3续航能力介绍
iOS14Beta3稳定性怎么样 iOS14Beta3升级建议介绍
网友评论