Is it possible to remove [“Page 1 of 20” view] in

2019-04-28 03:58发布

I can not get to a solution after much googling. I have a UIWebView with a PDF in it.

I do not want the view: "Page 1 of 20" The small view in the upper left corner when viewing a PDF file. It is possible to remove this?

3条回答
聊天终结者
2楼-- · 2019-04-28 04:27

I found a solution to your question... You can Hide the "Page 1 of 20" using following code :

for (UIView* subView in [webView subviews])
{
    if ([subView isKindOfClass:[UIScrollView class]]) {
        for (UIView* shadowView in [subView subviews])
        {
            if ([shadowView isKindOfClass:[UIImageView class]]) {
                [shadowView setHidden:YES];
            }
        }
    }
}

Hope this may be helpful to some one... Thanks...

查看更多
啃猪蹄的小仙女
3楼-- · 2019-04-28 04:42

This code is working on iOS9, 10 (tested)

    func hidePageNumberView(v: UIView) {
        for subView in v.subviews {
            if subView.isKindOfClass(UIImageView) || subView.isKindOfClass(UILabel) || subView.isKindOfClass(UIVisualEffectView){
                subView.hidden = true

                if subView.isKindOfClass(UILabel) {
                    if let sv = subView.superview {
                        sv.hidden = true
                    }
                }
            } else {
                hidePageNumberView(subView)
            }
        }
    }

Implement webView.scrollView.delegate and run above code in scrollViewDidScroll

Hope this help.

iOS 11 / Swift 4:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    hidePageNumberView(scrollView)
}

func hidePageNumberView(_ v: UIView) {
    for subView in v.subviews {
        if subView is UIImageView || subView is UILabel || subView is UIVisualEffectView {
            subView.isHidden = true

            if subView is UILabel {
                if let sv = subView.superview {
                    sv.isHidden = true
                }
            }
        } else {
            hidePageNumberView(subView)
        }
    }
}
查看更多
唯我独甜
4楼-- · 2019-04-28 04:46

Swift 3 and WKWebView

I get all the subviews of the WKWebView and then remove WKPDFPageNumberIndicator:

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
  let webViewSubviews = self.getSubviewsOfView(v: self.webView)
  for v in webViewSubviews {
    if v.description.range(of:"WKPDFPageNumberIndicator") != nil {
      v.isHidden = true // hide page indicator in upper left
    }
  }
}

func getSubviewsOfView(v:UIView) -> [UIView] {
  var viewArray = [UIView]()
  for subview in v.subviews {
    viewArray += getSubviewsOfView(v: subview)
    viewArray.append(subview)
  }
  return viewArray
}

You'll probably have to set webView.navigationDelegate = self

UPDATE (not tested) - Swift 4

Keep the getSubviewsOfView function from above and modify the webView function like this:

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
  let webViewSubviews = self.getSubviewsOfView(v: self.webView)
  for v in webViewSubviews {
    if v.isKind(of: UILabel.self) || v.isKind(of: UIImageView.self) || v.isKind(of: UIVisualEffectView.self) {
      v.isHidden = true
    }
  }
}
查看更多
登录 后发表回答