Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing shadows from UIWebView

I use a web view to display small pdf files. In the interest of aesthetics, I'd like to remove the grey border around the PDF. Is there any way around it? I've looked at various resources none of which seem to work or the solution no longer works in iOS5.

Also, is there any way of stopping the scroll if there's only one page?

Thanks.

like image 438
mattFllr Avatar asked Dec 12 '11 20:12

mattFllr


2 Answers

The shadows are actually UIImageView subviews of the UIScrollView (or the equivalent in iOS5 UIWebView).

So in iOS4:

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];
            }
        }
    }
}

and in iOS5 and above:

for (UIView* shadowView in [webView.scrollView subviews])
{
    if ([shadowView isKindOfClass:[UIImageView class]]) {
        [shadowView setHidden:YES];
    }
}
like image 185
Léo Natan Avatar answered Oct 23 '22 17:10

Léo Natan


Works great with iOS 9

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    for (UIView *object in webView.scrollView.subviews) {
        if ([NSStringFromClass([object class]) isEqualToString:@"UIWebPDFView"]) {
            UIView *pdfView = object;
            for (UIView *pdfObjectSubview in pdfView.subviews) {
                if ([NSStringFromClass([pdfObjectSubview class]) isEqualToString:@"UIPDFPageView"]) {
                    UIView *uiPDFPageView = pdfObjectSubview;
                    uiPDFPageView.layer.shadowOpacity = 0.0f;
                }
            }
        }
    }
}
like image 40
Pavel Volobuev Avatar answered Oct 23 '22 16:10

Pavel Volobuev