Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove gradient background from UIWebView?

How do remove the gradient from a UIWebView - the one that you see if you overscroll the top or bottom. This code

webView.backgroundColor = [UIColor whiteColor];

just changes the color of the gradient, it doesn't removes it. How can this be done?

(note: not the same question as UIWebView underside)

like image 711
cannyboy Avatar asked Jun 09 '10 19:06

cannyboy


4 Answers

Aha, yes terminology fail. I wouldn't call that a shadow at all, but c'est la vie. Here is my type-safe code to achieve the effect. To summarise: this will hide any image-view children of the scroll view. It's not as vulnerable to change as the (objectAtIndex:0) methods, so if Apple re-order the children of the webView control it will work fine, but still relies on the fact that the gradient effect is applied by imageviews parented to the scroll view (and that there is indeed a scrollview underpinning the web view).

{
    webView.backgroundColor = [UIColor whiteColor];
    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];
                }
            }
        }
    }
}
like image 119
MrCranky Avatar answered Nov 18 '22 20:11

MrCranky


To transparent the UIWebView and remove the scrolls.

 webView.opaque = NO;
 webView.backgroundColor = [UIColor clearColor];
 for(UIView *view in webView.subviews){      
      if ([view isKindOfClass:[UIImageView class]]) {
           // to transparent 
           [view removeFromSuperview];
      }
      if ([view isKindOfClass:[UIScrollView class]]) {
           UIScrollView *sView = (UIScrollView *)view;
           for (UIView* shadowView in [sView subviews]){
                //to remove shadow
                if ([shadowView isKindOfClass:[UIImageView class]]) {
                     [shadowView setHidden:YES];
                }
           }
      }
 }

for hide scroll indicators

like image 3
damithH Avatar answered Nov 18 '22 19:11

damithH


You mean the shadow? Remove UIWebView Shadow?

like image 2
Brian Avatar answered Nov 18 '22 19:11

Brian


The only way I found how to do this was :

for(UIView *aView in [[[webView subviews] objectAtIndex:0] subviews]) { 
        if([aView isKindOfClass:[UIImageView class]]) { aView.hidden = YES; } 
}

It just just steps thru the subviews of UIWebView and removes the view if it is an image view.

I haven't put this in any App Store apps, so I don't know if Apple would accept it.

EDIT: Brian's link provides more details.

like image 1
cannyboy Avatar answered Nov 18 '22 20:11

cannyboy