'How to eliminate PDFView "page shadow"?

When an iOS PDFView is added to a UIView, the PDFView's page area adds a shadow-like border. Is there a way to eliminate the shadow?

I know a few messy ways to do this: Extend the bounds off-screen, overlay a white UIView to hide the shadows, or modify the private PDFPageView (to clip-to-bounds). I specifically don't want the bounds offscreen here, and prefer not to get messy with other hacks.

Example attached. (IRS form used for example here; app has nothing to do with the IRS...) enter image description here



Solution 1:[1]

Update: Apple responded to my Radar that a new property, PDFView.pageShadowsEnabled, has been added to iOS 12, beta 3. This is now the right way to hide the shadow. Hooray!

https://developer.apple.com/documentation/pdfkit/pdfview/3013838-pageshadowsenabled?changes=latest_minor

Pre-iOS 12 info below:

I confirmed with Apple (WWDC 2018 lab) there is no official way to hide the shadow. I was told there's an internal-only method to do this, and asked to file a Radar to expose that method. Radar # 40847614 if anyone wants to dupe.

Meanwhile I'm deep-diving the view hierarchy, and clipping everything to bounds. I don't like it, but it seems to work. The shadow returns on rotation, so I call this both in viewWillAppear and viewWillTransitionToSize.

-(void)removeShadowFromPDFView:(UIView *)view {
    //Deep-dive into pdfView and set all views to clipsToBounds = YES

    view.clipsToBounds = YES;

    if ([view subviews].count == 0) {
        //No subviews to examine
        return;
    }

    for (UIView *subview in view.subviews) {
        view.clipsToBounds = YES;
        [self removeShadowFromView:subview];
    }
}

Solution 2:[2]

I had a similar problem with a split view pane. What I did was to examine each view in the sub views, and each of their subviews, also layers, until identified the problem view (took some time). Then I just made that view hidden or opaque.

When I tested for the uiview subclass, I did not hardcore the name but constructed it with a format string so as not to trigger some automated test of my app (which Apple approved).

Solution 3:[3]

In Swift you can disable page shadows using below line of code

pdfView.pageShadowsEnabled = false

Solution 4:[4]

Actually you should change two properties to eliminate any borders appearance

pdfView.pageShadowsEnabled = false (iOS 12+)
pdfView.backgroundColor = .clear

By the way, because content itself has insets, you may shift it instead of changing backgroundColor:

extension UIView {
    func removeShadow() {
        func shift(_ view: UIView) {
            let origin = view.frame.origin
            let insets = UIEdgeInsets(
                top: -origin.y,
                left: -origin.x,
                bottom: -origin.y,
                right: -origin.x
            )
            view.frame = view.frame.inset(by: insets)
        }
        
        shift(self)
        
        self.subviews.forEach {
            shift($0)
            $0.removeShadow()
        }
    }
}

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 David H
Solution 3 Nazrul Islam
Solution 4 Eugene