Tuesday, June 4, 2013

UIScrollView indicatorStyle example in Objective C (iOS).


UIScrollView indicatorStyle

The style of the scroll indicators.

@property(nonatomic) UIScrollViewIndicatorStyle indicatorStyle

Discussion of [UIScrollView indicatorStyle]
The default style is UIScrollViewIndicatorStyleDefault. See “Scroll Indicator Style” for descriptions of these constants.

UIScrollView indicatorStyle example.
You can use "indicatorStyle" property:

[scrollView1 setBackgroundColor:[UIColor blackColor]];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;

Example of [UIScrollView indicatorStyle].
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;
        }
    }

UIScrollView indicatorStyle example.
[scrollView3 setBackgroundColor:[UIColor clearColor]];
[scrollView3 setCanCancelContentTouches:NO];
[scrollView3 setUserInteractionEnabled:YES];
[scrollView3 setScrollEnabled:YES];
[scrollView3 setMinimumZoomScale:1.0];
[scrollView3 setMaximumZoomScale:2.0];
scrollView3.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView3.clipsToBounds = NO;
scrollView3.pagingEnabled = YES;
scrollView3.userInteractionEnabled = YES;
scrollView3.multipleTouchEnabled = YES;

End of UIScrollView indicatorStyle example article.