获取webView内容高度,自适应高度

很多时候需要先计算出webview的内容高度再去自适应高度,其实我们可以等UIWebViewDelegate的方法走完更新一下约束即可

//#pragma mark - UIWebViewDelegate

  • (void)webViewDidFinishLoad:(UIWebView *)aWebView {
    CGRect frame = aWebView.frame;
    frame.size.height = 1;
    aWebView.frame = frame;
    CGFloat yHeight = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
    frame.size.height = yHeight;
    aWebView.frame = frame;
    //更新webVeiw的约束
    _webViewHeightConstraint.constant = yHeight;
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容