I have a custom view that adds a WKWebView like this:
override func awakeFromNib() {
super.awakeFromNib()
loadWebView()
}
func loadWebView() {
pdfWebView = WKWebView(frame: .zero)
pdfWebView.navigationDelegate = self
pdfWebView.translatesAutoresizingMaskIntoConstraints = false
pdfWebView.isHidden = true
self.addSubview(pdfWebView)
... add constrains to self anchors - top, left, right, bottom
}
When loads finishes, I have this:
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8, execute: {
SVProgressHUD.dismiss()
webView.isHidden = false
webView.isOpaque = true
webView.adjustInsets()
})
}
I had to adjust the insets, because on iPhone X, sometimes the pdf sticked to the bottom, instead to the top.
extension WKWebView {
func adjustInsets() {
parentViewController?.automaticallyAdjustsScrollViewInsets = false
scrollView.contentInset = .zero
scrollView.scrollIndicatorInsets = .zero
scrollView.contentOffset = .zero
}
}
The result is this:
There is a gray border.
I have tried this:
setting view's, pdfWebView and pdfWebView.scrollView background with .white or .clear
webView.isOpaque = false( this is the single one that removes the bottom part of the gray - but not the border)
I have used an extension to set the .clear color to all child views
extension UIView { func clearBackgrounds() { self.backgroundColor = UIColor.clear for subview in self.subviews { subview.clearBackgrounds() } } }
Nothing works to remove the border. I can not edit the pdf, because this one is downloaded from ws and used in multiple apps.

