Blog Posts

Getting rid of the shadow in UIWebView

Forget my pickiness and if this post is totally unrelated to you, let me know but I need to post this. From time to time I try out new iPhone apps and it always bugs me that devs are not able to get rid of the shadow in UIWebView. Granted there is no API for that, but it's not very hard to figure out how to do it. You just have to care enough.

A good example is Reeder. Reeder renders its text in a UIWebView and there are no shadows on the top or on the bottom.

Reeder Screenshot

A shocking bad example is Instapaper:

Instapaper Screenshot

Here is what I do in Instacast to get rid of the shadows and to make the background view white like the web content:

for(UIScrollView* webScrollView in [self.webView subviews]) {
    if ([webScrollView isKindOfClass:[UIScrollView class]]) {
        for(UIView* subview in [webScrollView subviews]) {
            if ([subview isKindOfClass:[UIImageView class]]) {
                ((UIImageView*)subview).image = nil;
                subview.backgroundColor = [UIColor whiteColor];
            }
        }
    }
}

Apple is using simple UIImageViews to draw the background pattern and the shadows. You just have to make these image views hidden. The result is a clean text view with no shadows and background colors whatsoever.

Instacast Screenshot

The code does not use any private API and is totally valid. In fact I use this technique of traversing subviews of Apple views a lot. Everytime when there is public API missing, you can do this. Another example would be the UISearchBar. You can traverse the subviews and make the actual bar invisible and you get a nice UISearchField that would otherwise be private to use. This technique is App Store approval process approved.

April 5th, 2011 • Permalink


More articles about Blog Posts

05/09/2012 - New Specs on Podlove.org
05/09/2012 - Excellent Write-up of Instacast 2.0
05/07/2012 - Instacast 2.0 Available
05/06/2012 - Instacast HD Rejected over Flattr Integration
05/02/2012 - Multi-Format Podcast Feeds
04/26/2012 - Instacast 2.0 First Impressions
04/05/2012 - Patching iCloud Sync
03/29/2012 - The Podlove Initiative
03/28/2012 - Auphonic now Open for the Public
03/26/2012 - What's next with Instacast?
03/26/2012 - State of Support and iCloud