Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView scroller color?

I have a UIScrollView which I am applying a black background, which blends in the scrollbar. I have been looking for a way to change the scrollbars color to white, but I cannot figure it out. Is there a proper way of doing this?

like image 260
Kyle Avatar asked Jun 21 '10 10:06

Kyle


2 Answers

You can use "indicatorStyle" property:

[scrollView1 setBackgroundColor:[UIColor blackColor]];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
like image 112
mav Avatar answered Nov 05 '22 21:11

mav


Both UIScrollView indicator are sub view of UIScrollView. So, we can access subview of UIScrollView and change the property of subview.

1 .Add UIScrollViewDelegate

@interface ViewController : UIViewController<UIScrollViewDelegate>
@end

2. Add scrollViewDidScroll in implementation section

-(void)scrollViewDidScroll:(UIScrollView *)scrollView1
{
    //get refrence of vertical indicator
    UIImageView *verticalIndicator = ((UIImageView *)[scrollView.subviews objectAtIndex:(scrollView.subviews.count-1)]);
    //set color to vertical indicator
    [verticalIndicator setBackgroundColor:[UIColor redColor]];


    //get refrence of horizontal indicator
    UIImageView *horizontalIndicator = ((UIImageView *)[scrollView.subviews objectAtIndex:(scrollView.subviews.count-2)]);
    //set color to horizontal indicator
    [horizontalIndicator setBackgroundColor:[UIColor blueColor]];
}

Note:- Because these indicator update every time when you scroll (means reset to default). SO, we put this code in scrollViewDidScroll delegate method.

enter image description here

like image 32
Vineet Choudhary Avatar answered Nov 05 '22 23:11

Vineet Choudhary