Removing shadows from UIWebView

♀尐吖头ヾ 提交于 2019-11-30 13:48:33

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

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!