Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michal-majchrzycki/064aa20eb08774b2f595eb101fc84ce7 to your computer and use it in GitHub Desktop.
Save michal-majchrzycki/064aa20eb08774b2f595eb101fc84ce7 to your computer and use it in GitHub Desktop.
func setSelectedItemFromScrollView(_ scrollView: UIScrollView) {
if calendarCollectionView == scrollView {
let center = CGPoint(x: scrollView.center.x + scrollView.contentOffset.x, y: scrollView.center.y + scrollView.contentOffset.y)
let index = calendarCollectionView.indexPathForItem(at: center)
if index != nil {
calendarCollectionView.scrollToItem(at: index!, at: .centeredHorizontally, animated: true)
self.calendarCollectionView.selectItem(at: index, animated: false, scrollPosition: [])
self.collectionView(self.calendarCollectionView, didSelectItemAt: index!)
self.selectedDate = (index?.row)!
self.selectedDateLabel.text = self.calendarArray?[(index?.row)!] as! String?
}
else {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment