13

I'm using UIWebView for show a simple HTML page. When I scroll the page (over the top or over the bottom) a shadow gray appears behind!! Can I remove or avoid this bad effect?

Thx

P.S. UIWebView, View container, are all background clear and opaque NO!!

Undolog
  • 562
  • 2
  • 9
  • 20

8 Answers8

23

The shadows are of class UIImageView. You can loop through the views of the first subview of UIWebView and just hide any views that match UIImageView.

id scrollview = [webView.subviews objectAtIndex:0];    
for (UIView *subview in [scrollview subviews])
  if ([subview isKindOfClass:[UIImageView class]])
   subview.hidden = YES;

Disclaimer: the view hierarchy could change in the future and this would not work causing the shadows to come back.

Adolfo
  • 4,969
  • 4
  • 26
  • 28
  • i put your code on the viewDidLoad , and doesn't work . – Mc.Lover Mar 19 '10 at 09:33
  • [subview isKindOfClass:[UIImageView class]] would be more correct, but the proper answer is given by Undolog. – Jason Foreman Nov 15 '10 at 19:37
  • Thanks, I updated it to be "more correct". :) – Adolfo Nov 15 '10 at 22:08
  • There's also no need for the first line, since you can access the `scrollView` directly, so the loop could be changed to: `for (UIView *subview in [webView.scrollview subviews])` – theTRON Nov 15 '11 at 00:00
  • The shadow is back with iOS 5 – zeiteisen Dec 12 '11 at 10:03
  • @zeiteisen I had the same problem with iOS 5.1 and removing the image views did not help. To solve the problem, I moved the web view up by about 4px so that the shadow ended up underneath the navigation bar. Moreover, I disabled bouncing of the scroll view (which is a public property of `UIWebView` in iOS 5). – Raginmari Aug 20 '12 at 12:54
5

Check this out worked for me..

UIScrollView *scrollview = [webView.subviews objectAtIndex:0];
scrollview.bounces=NO;

Nilesh Tupe
  • 7,655
  • 5
  • 25
  • 30
  • that property is just webView.scrollView and just makes it so you can't scroll. You haven't removed the annoying shadow. – Adam Waite Apr 23 '13 at 10:31
4
for (UIView *view in self.webView.scrollView.subviews) {
        if ([view isKindOfClass:[UIImageView class]]) {
            view.hidden = YES;
        }
    }

Why Apple would be reject this method, there is no undocumented and private part :) You find any view, check their class, and hide... You are not delete, or rewrite methods.. You not modified (rewrite) any parts of object... only hide, No ?

iTux
  • 1,946
  • 1
  • 16
  • 20
2

It is not possible! Over the web there are some solution that using private apple methods (undocumented api & functions). So, apple could refuse your app.

Undolog
  • 562
  • 2
  • 9
  • 20
0

For anyone in this situation where scrolling is not required, because all your content fits, calling the sizeToFit method on the UIWebView will eliminate these shadows.

Rob Reuss
  • 1,400
  • 10
  • 20
0

put uiwebview on uiscrollview and disable uiwebview scrolling.

0

You can do this.

webView.backgroundColor = [UIColor clearColor]; and out a nice UIImageView at the background.

This is simple and easy.

Dinesh
  • 81
  • 1
  • 5
0
for (id subview in _webView.subviews)
            if ([[subview class] isSubclassOfClass: [UIScrollView class]]) {
                for (UIView *scrollSubview in [subview subviews])
                    if ([[scrollSubview class] isSubclassOfClass:[UIImageView class]])
                        scrollSubview.hidden = YES;
            }

This solution will not be rejected.

rowwingman
  • 5,589
  • 7
  • 33
  • 50