Created
April 6, 2017 06:57
-
-
Save michal-majchrzycki/064aa20eb08774b2f595eb101fc84ce7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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