I implemented logic in func scrollViewDidScroll(_ scrollView: UIScrollView)
but it is not working properly.
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let principal = scrollView.contentSize.width - scrollView.frame.width
let progress = scrollView.contentOffset.x / principal
var progresss = max(0, min(1, progress))
progressBar.setProgress(Float(progresss), animated: true)
new = Int((CGFloat(arrayTagBasedFilter.count)) * progresss)
new = Int(max(0, min(arrayTagBasedFilter.count-1, new)))
let newIndex = IndexPath(item: new, section: 0)
if let selectedIndexForFilter = selectedIndexForFilter
{
if let cell = collectionViewFilter.cellForItem(at: selectedIndexForFilter) as? BoostFilterCVCell
{
cell.lblTitle.textColor = .black.withAlphaComponent(0.5)
}
}
if let cell = collectionViewFilter.cellForItem(at: newIndex) as? BoostFilterCVCell
{
selectedIndexForFilter = newIndex
cell.lblTitle.textColor = .black
progressView.frame = CGRect(origin: CGPoint(x: cell.frame.origin.x, y: collectionViewFilter.frame.origin.y - 50),
size: CGSize(width: cell.frame.width, height: 1))
}
}