3

I am trying to display PDF file in UIWebView. Working fine. But, PDF view having shadow on back side. I dont know how to remove it completely.

My Code:

func webViewDidFinishLoad(webView: UIWebView) {
    for object in webView.scrollView.subviews
    {
            if NSStringFromClass((object.classForCoder)) == "UIWebPDFView"
            {
                let pdfVi = object

                for pdf_view_sub in (pdfVi.subviews)
                {
                    if NSStringFromClass((pdf_view_sub.classForCoder)) == "UIPDFPageView"
                    {
                        let pdfVi_lay = pdf_view_sub
                        pdfVi_lay.layer.shadowOpacity = 0.0
                    }
                }
            }
        }
}

My Image

enter image description here

The above code is not working when we start scrolling. That means, if we are trying to scroll upwards, automatically same shadow appearing on PDF's backside.

McDonal_11
  • 3,935
  • 6
  • 24
  • 55

2 Answers2

0

In my case, I have a similar situation. I need to change the border and the background color in Swift3 in a UIWebView only for PDF viewer, and it is important to keep another color for other files than PDF.

It is not the exact solution, but it is a solution suitable for your problem. Anyway this solution is useful for more scenarios.

Here is my solution:

    var color = UIColor.white
    for object in webView.scrollView.subviews {
        if NSStringFromClass((object.classForCoder)) == "UIWebPDFView" {
            for pdf in (object.subviews) {
                if NSStringFromClass((pdf.classForCoder)) == "UIPDFPageView" {
                    color = UIColor(red:0.502, green:0.502, blue:0.502, alpha:1)
                }
            }
        }
    }

    webView.backgroundColor = color
    webView.layer.shadowOpacity = 0.0
    webView.scrollView.backgroundColor = color
    webView.scrollView.layer.shadowOpacity = 0.0
    for object in webView.scrollView.subviews {
        object.backgroundColor = color
        object.layer.shadowOpacity = 0.0
        if NSStringFromClass((object.classForCoder)) == "UIWebPDFView" {
            object.backgroundColor = color
            object.layer.shadowOpacity = 0.0
            for pdf in (object.subviews) {
                pdf.backgroundColor = color
                pdf.layer.shadowOpacity = 0.0
                if NSStringFromClass((pdf.classForCoder)) == "UIPDFPageView" {
                    pdf.backgroundColor = color
                    pdf.layer.shadowOpacity = 0.0
                }
            }
        }
    }
jalopezsuarez
  • 414
  • 4
  • 13
0

New in iOS 12 and PDFView of PDFKit we have a property we can set to false

pageShadowsEnabled = false
RyanTCB
  • 7,400
  • 5
  • 42
  • 62