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?
You can use "indicatorStyle" property:
[scrollView1 setBackgroundColor:[UIColor blackColor]];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
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.
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