Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 735
Mitch Cohen Avatar asked Jan 03 '23 08:01

Mitch Cohen


1 Answers

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];
    }
}
like image 114
Mitch Cohen Avatar answered Jan 05 '23 17:01

Mitch Cohen