I want to know index of current scrolled page in UIScrollView. I have searched through many sites by none helps. Any suggestions are welcome.
Try this
//Horizontal
NSInteger pagenumber = scrollView.contentOffset.x / scrollView.bounds.size.width;
//Vertical
NSInteger pagenumber = scrollView.contentOffset.y / scrollView.bounds.size.height;
For those needing code (swift) , the UIScrollViewDelegate provides the method, this uses the horizontal example from above
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
print("END Scrolling \(scrollView.contentOffset.x / scrollView.bounds.size.width)")
index = Int(scrollView.contentOffset.x / scrollView.bounds.size.width)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With