I want to change the color of horizontal scroll bar Indicator of UICollectionView, Apart from default, black or white which could be done in storyboard?
Asked
Active
Viewed 3,203 times
0
-
3see this once http://stackoverflow.com/questions/12005187/ios-changing-uiscrollview-scrollbar-color-to-different-colors – Anbu.Karthik Aug 08 '16 at 10:30
-
Please specify the language in which you wanted to use i.e swift or objective C . I saw somebody answered but they have the confusion. So please write whole content for your question. – ManiaChamp Aug 08 '16 at 10:55
2 Answers
1
Please refer the below code for the Scrolling UICollection View Horizontal Bar color change also refer below link for more information and download sample code from that.
http://blog.mosheberman.com/coloring-the-ios-uiscrollviewindicators/
func setScrollIndicatorColor(color: UIColor) {
for view in self.tableView.subviews {
if view.isKindOfClass(UIImageView.self),
let imageView = view as? UIImageView,
let image = imageView.image {
imageView.tintColor = color
imageView.image = image.imageWithRenderingMode(.AlwaysTemplate)
}
}
self.tableView.flashScrollIndicators()
}

ashmi123
- 710
- 1
- 6
- 21
-
asfmi - your answer is fine , but the questioner needs the answer in objective C – Anbu.Karthik Aug 08 '16 at 10:39
-
Getting Error in Value of type 'UIView' has no member 'isKindOfClass' – Chandan Jee Jun 13 '20 at 16:11
-
How can call this func for collectionView horizontal scroll color ? – Chandan Jee Jun 13 '20 at 16:18
0
You can use delegate method : 'scrollViewDidScroll' and add
//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]];

Maulik Pandya
- 2,200
- 17
- 26