I need to create a WebView programmatically in ViewController-e with ScrollView and only when necessary. By default it is not. You also need to knead it between two Label. Also, I’m interested in how to secure it with AutoLayout. Thank.

iOS 9. *, Swift 3

enter image description here

    1 answer 1

     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)) }