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:
(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:
(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?
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;
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.
Scan the subviews and test for a UIScrollView. You can then programatically set the indicator.
There is no public API for this in the 2.x SDK. File a bug/case/radar asking for it in 3.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With