Last active
April 17, 2025 18:30
-
-
Save catalinaturlea/cd1722c2d98dca5f92d57a3a7f0dc9b0 to your computer and use it in GitHub Desktop.
Adding a WKWebView programmatically - together with the constraints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private weak var webView: WKWebView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// This is needed when using an iOS target < iOS 11.0 - there was a storyboard bug which does not allow instantiating WKWebView from the Storyboard or Xib file | |
let webView = WKWebView() | |
self.webView.translatesAutoresizingMaskIntoConstraints = false | |
self.view.addSubview(webView) | |
self.webView = webView | |
// Add the constraints to fill in the whole view | |
NSLayoutConstraint.activate([ | |
self.webView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor), | |
self.webView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor), | |
self.webView.topAnchor.constraint(equalTo: self.view.topAnchor), | |
self.webView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor), | |
]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment