美文网首页iOS 开发那些事 ~
获取webView内容高度,自适应高度

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

作者: hexuren | 来源:发表于2017-12-12 15:18 被阅读0次

很多时候需要先计算出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;
    }

相关文章

网友评论

    本文标题:获取webView内容高度,自适应高度

    本文链接:https://www.haomeiwen.com/subject/drknixtx.html