美文网首页
iOS WebView获取高度

iOS WebView获取高度

作者: 啊哈阿兹猫 | 来源:发表于2019-07-12 09:17 被阅读0次

我们想要的结果是将 WebView 设置为不可滚动,与原生的 UI 融合在一起,那这种情况下,我们必须得到 WebView 的内容高度,让 WebView 的高度与它所需要加载的网页的内容高度一致

@interface ProductDetailVC ()<UIWebViewDelegate>

//xib连线

@property (weak, nonatomic) IBOutlet UIWebView *produxtWebView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *webviewHeight;

添加代理

_produxtWebView.delegate = self;

 [_produxtWebView loadHTMLString:_detail.content baseURL:nil];

//代理方法

-(void)webViewDidFinishLoad:(UIWebView*)webView

{

    _webviewHeight.constant = webView.scrollView.contentSize.height;

    [self.view layoutIfNeeded];

}

相关文章

网友评论

      本文标题:iOS WebView获取高度

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