Tiago Amaral
Tiago Amaral

Reputation: 161

How remove or hide page counter of PDF from WKWebview?

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.

Upvotes: 2

Views: 802

Answers (2)

Daniele Ceglia
Daniele Ceglia

Reputation: 845

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.

Upvotes: 1

Tiago Amaral
Tiago Amaral

Reputation: 161

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
}

Upvotes: 4

Related Questions