我们想要的结果是将 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];
}
网友评论