Skip to content

Instantly share code, notes, and snippets.

@imnaveensharma
Last active July 10, 2024 01:45
Show Gist options
  • Save imnaveensharma/22e48fdfe74f936ba5d71d11b8ddc84f to your computer and use it in GitHub Desktop.
Save imnaveensharma/22e48fdfe74f936ba5d71d11b8ddc84f to your computer and use it in GitHub Desktop.
To change scroll view indicator color
// MARK: - Extension :: UIScrollViewDelegate ::
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//--- Change Scroll View Indicator Color ---//
if #available(iOS 13, *) {
let verticalIndicatorView = (scrollView.subviews[(scrollView.subviews.count - 1)].subviews[0])
let horizontalIndicatorView = (scrollView.subviews[(scrollView.subviews.count - 2)].subviews[0])
let colors = [UIColor(hex: "#E54F4F")!.cgColor, UIColor(hex: "##E61C1C")!.cgColor, UIColor(hex: "#8E0202")!.cgColor]
verticalIndicatorView.backgroundColor = UIColor.clear
verticalIndicatorView.setGradient(colors: colors, angle: 90.0)
horizontalIndicatorView.backgroundColor = UIColor.clear
horizontalIndicatorView.setGradient(colors: colors, angle: 90.0)
} else {
let colors = [UIColor(hex: "#E54F4F")!.cgColor, UIColor(hex: "##E61C1C")!.cgColor, UIColor(hex: "#8E0202")!.cgColor]
if let verticalIndicatorView: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 1)] as? UIImageView) {
verticalIndicatorView.backgroundColor = UIColor.clear
verticalIndicatorView.setGradient(colors: colors, angle: 90.0)
}
if let horizontalIndicatorView: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 2)] as? UIImageView) {
horizontalIndicatorView.backgroundColor = UIColor.clear
horizontalIndicatorView.setGradient(colors: colors, angle: 90.0)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment