2

How i can remove or hide a page counter from WKWebview when load a PDF file?

f

I tried the solutions that are on this link (using iOS 13.3, Swift 4.2.), but they don't work.

Tiago Amaral
  • 161
  • 7

2 Answers2

4

With the help of a friend, we found a solution.   In the delegate method, we can hide the UIView which contains the page counter:

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    hidePDFPageCount(webView)
}

func hidePDFPageCount(_ webView: WKWebView){
    guard let last = webView.subviews.last else {
        return
    }

    last.isHidden = true
}
Tiago Amaral
  • 161
  • 7
1

Objective-C version, tested on iOS 14:

#pragma mark - WKNavigationDelegate

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    UIView *lastView = webView.subviews.lastObject;
    
    if (lastView != nil && ![lastView isKindOfClass:[UIScrollView class]]) {
        lastView.hidden = YES;
    }
}

Compared to the accepted answer I had to add:

![lastView isKindOfClass:[UIScrollView class]]

Because the last view is not always the page counter.

Daniele Ceglia
  • 849
  • 8
  • 12