I have set WKWebView
bottom constraint to superview but it won't display till superview instead displays content till safe area.
Here is the problem image that displays the bottom part doesn't fill properly.
And here is the hierarchy of view and constraints image
And code to setup WebView constraints with container view
let wv = WKWebView(frame: containerView.frame, configuration: wvConfig)
webView = wv
containerView.addSubview(wv)
// setup constraints
wv.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
wv.trailingAnchor.constraint(equalTo: containerView.trailingAnchor).isActive = true
wv.leadingAnchor.constraint(equalTo: containerView.leadingAnchor).isActive = true
wv.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
wv.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
} else {
NSLayoutConstraint(item: wv, attribute: .top, relatedBy: .equal, toItem: containerView, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
NSLayoutConstraint(item: wv, attribute: .leading, relatedBy: .equal, toItem: containerView, attribute: .leading, multiplier: 1.0, constant: 0).isActive = true
NSLayoutConstraint(item: wv, attribute: .trailing, relatedBy: .equal, toItem: containerView, attribute: .trailing, multiplier: 1.0, constant: 0).isActive = true
NSLayoutConstraint(item: wv, attribute: .bottom, relatedBy: .equal, toItem: containerView, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true
}
So, Can anyone rectify issue here?
Some certain URL's it works, but not for all. Why?
Replace containerview with view in bottom constraint because root is view.
According to the given screenshot, bottom constraint is applied in to safe area.Add bottom constraint into SuperView.
The following subclassed WKWebView might solve your problem:
The above snipped taken from
Full Code:
output: 1. iOS version > 10
your code looks fine, your problem might come from the
containerView
constraints.If you are using storyboards, Xcode is probably setting constraints on safe area. In that case you should handle all the constraints programmatically.
I am trying to reproduce the same issue, used your approach but didn't get any issue regarding bottom space.
Everything is working fine for me.
Output -
Please let me know if I'm missing something.
UPDATE -
Issue is with scrollView of WKWebview.
In safe area WKScrollView.adjustedContentInset is set to {0, 0, 34, 0}.
To avoid this use
Final output -