Karthikeyan Bose Karthikeyan Bose - 1 month ago 18
iOS Question

How to change UIScrollView Indicator color?

When I use UIColor.blue its changing, but when I try to apply RGB, its not reflected in scrollview indicator.

func scrollViewDidScroll(_ scrollView: UIScrollView) {
let verticalIndicator: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 1)] as! UIImageView)
verticalIndicator.backgroundColor = UIColor(red: 211/255, green: 138/255, blue: 252/255, alpha: 1)
// verticalIndicator.backgroundColor = UIColor.blue

}

Answer

I think problem is here

verticalIndicator.backgroundColor = UIColor(red: 211/255, green: 138/255, blue: 252/255, alpha: 1)

Change to

verticalIndicator.backgroundColor = UIColor(red: 211/255.0, green: 138/255.0, blue: 252/255.0, alpha: 1).

The result of division 211/255 is type of integer so it return only 0 or 1 (in this case i think it is 0).