1 初始化
self.webView.delegate = self;
_webView.scrollView.bounces = NO;
_webView.scrollView.showsHorizontalScrollIndicator = NO;
_webView.scrollView.scrollEnabled = NO;
[_webView sizeToFit];
2 获取webview的高度
//webview 高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *webViewConstraintHeight;
3 设置新的高度
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
CGRect frame = webView.frame;
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
self.webViewConstraintHeight.constant = frame.size.height;
}