Remove UIWebView Shadow?

Does anyone know if its possible to remove the shadow that is placed on the UIWebView window?

Example: http://uploadingit.com/files/1173105_olub5/shadow.png

If its possible how do you do it?

Thanks


Solution 1:

This is a cleaner alternative to "Nikolai Krill" solution. This only hides UIImageViews within the UIWebView and not the UIWebBrowserView.

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

Thanks James

Solution 2:

the small for loop is very dangerous because it can crash if apple changes the number of the subviews.

this way it does at least not crash when something changes:

if ([[webView subviews] count] > 0)
{
    for (UIView* shadowView in [[[webView subviews] objectAtIndex:0] subviews])
    {
        [shadowView setHidden:YES];
    }

    // unhide the last view so it is visible again because it has the content
    [[[[[webView subviews] objectAtIndex:0] subviews] lastObject] setHidden:NO];
}

Solution 3:

There is a private method with the selector setAllowsRubberBanding: that takes a BOOL value. If passed NO, you will not be able to scroll the web view past the top or bottom of the content area, but will still let you scroll through the web view normally. Unfortunately, this method IS private, and your app will likely not be allowed onto the store if you use it.

You could, however, potentially try and extract the method implementation and bind it to a different selector that you've created, using the dynamic nature of Objective-C's runtime.

Still, the method is private and may no longer exist in future versions of the OS. If you still want to try, here's some sample code that will extract the setAllowsRubberBanding: method implementation and call it for you.

static inline void ShhhDoNotTellAppleAboutThis (UIWebView *webview)
{
    const char *hax3d = "frgNyybjfEhooreOnaqvat";
    char appleSelName[24];

    for (int i = 0; i < 22; ++i)
    {
        char c = hax3d[i];
        appleSelName[i] = (c >= 'a' && c <= 'z') ? ((c - 'a' + 13) % 26) + 'a' : ((c - 'A' + 13) % 26) + 'A';
    }
    appleSelName[22] = ':';
    appleSelName[23] = 0;

    SEL appleSEL = sel_getUid(appleSelName);

    UIScrollView *scrollView = (UIScrollView *)[webview.subviews objectAtIndex:0];
    Class cls = [scrollView class];
    if (class_respondsToSelector(cls, appleSEL) == NO)
    {
        return;
    }

    IMP func = class_getMethodImplementation(cls, appleSEL);
    func(scrollView, appleSEL, NO);
}

Please note that this will probably still get caught by Apple's static analyzer if you choose to submit an app using this code to the AppStore.