Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you tell UIWebView to use a white indicator style?

I'm running into a case where I have in-application HTML documentation that uses a dark background, but the default scroll indicator for UIWebView is getting lost in that background. The following is an example of this:

Image of UIWebView dark scroller
(source: sunsetlakesoftware.com)

With UIScrollView, which UIWebView resembles in its behavior, you can set the indicatorStyle property to UIScrollViewIndicatorStyleWhite, which results in the desired behavior:

alt text
(source: sunsetlakesoftware.com)

I can't seem to find a similar property in the exposed interface for UIWebView. Is there a CSS trick or other way to force the scroll indicator to a lighter style?

like image 317
Brad Larson Avatar asked Mar 31 '09 19:03

Brad Larson


4 Answers

Starting iOS 5.0 onwards, one can now customize the scrolling behavior of the web view by accessing the 'scrollview' property to achieve the desired functionality:

webView.scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
like image 120
Azeem Shaikh Avatar answered Oct 13 '22 23:10

Azeem Shaikh


If you do want to scan the subviews and attempt to gracefully fail if something changes in the future this currently works:

    //set a white scroll bar
    for (UIView *subview in [webView subviews]) {
        if ([subview isKindOfClass:NSClassFromString(@"UIScroller")] || [subview isKindOfClass:NSClassFromString(@"UIScrollView")]) {
            if ([subview respondsToSelector:@selector(setIndicatorStyle:)]) {
                [(UIScrollView *)subview setIndicatorStyle:UIScrollViewIndicatorStyleWhite];
            }
            break;
        }
    }

Though things could still break in the future if setIndicatorStyle: changes to expect a non-enumerated value... but I doubt that would happen.

like image 41
Brandon Avatar answered Oct 13 '22 23:10

Brandon


Scan the subviews and test for a UIScrollView. You can then programatically set the indicator.

like image 27
amattn Avatar answered Oct 13 '22 23:10

amattn


There is no public API for this in the 2.x SDK. File a bug/case/radar asking for it in 3.0.

like image 1
Mike Abdullah Avatar answered Oct 13 '22 23:10

Mike Abdullah