var webView: WKWebView? func createWebView() { self.webView = WKWebView() let webViewConfiguration = WKWebViewConfiguration() self.webView = WKWebView(frame: .zero, configuration: webViewConfiguration) self.webView.translatesAutoresizingMaskIntoConstraints = false self.scrollView.addSubview(webView) self.webView.addConstraint(NSLayoutConstraint(item:self.webView, attribute: .top, relatedBy: .equal, toItem:self.topLabel, attribute: .bottom, multiplier:1, constant:0)) self.webView.addConstraint(NSLayoutConstraint(item:self.webView, attribute: .bottom, relatedBy: .equal, toItem:self.bottomLabel, attribute: .top, multiplier:1, constant:0)) self.webView.addConstraint(NSLayoutConstraint(item:self.webView, attribute: .width, relatedBy: .equal, toItem:self.scrollView, attribute: .width, multiplier:1, constant:0)) self.webView.addConstraint(NSLayoutConstraint(item:self.webView, attribute: .centerX, relatedBy: .equal, toItem:self.scrollView, attribute: .centerX, multiplier:1, constant:0)) }