mattFllr
mattFllr

Reputation: 253

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.

Upvotes: 8

Views: 3997

Answers (4)

kalpa
kalpa

Reputation: 982

This is worked for me. I am using navigation Controller I hope it will help

self.navigationController.navigationBar.translucent = NO;

One more way is there, Just go to storyboard and select Controller where the web view is present. And go to attribute inspector and uncheck the

adjust scroll view insects

Upvotes: 0

Pavel Volobuev
Pavel Volobuev

Reputation: 149

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

Upvotes: 3

Léo Natan
Léo Natan

Reputation: 57040

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

Upvotes: 9

FuePi
FuePi

Reputation: 1986

Try to remove the border and shadow:

[[yourView layer] setBorderColor: [[UIColor clearColor] CGColor]];
[[yourView layer] setBorderWidth: 0.0f];
[[yourView layer] setShadowColor: [[UIColor clearColor] CGColor]];
[[yourView layer] setShadowOpacity: 0.0f];
[[yourView layer] setShadowOffset: CGSizeMake(0.0f, 0.0f)];

Upvotes: 0

Related Questions