0

I have added 10 labels to to display 0 to 9 in UIScrollView, User can see only one label in UIScrollView visible part. User needs to scroll to see other labels. How to determine which label is currently visible in UIScrollView after scroll view decelerating.

enter image description here

Thanks in advance

Prasad
  • 1,904
  • 4
  • 19
  • 24

3 Answers3

1

Use the scroll view's contentOffset and calculate how many "pages" down they have scrolled by dividing the y offset by the content size height.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
1

When scrolling is complete compare contentOffset value with labels positions or view to see which label is currently shown:

Use this method for getting scrolled position:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"%f", scrollView.contentOffset.y);

    //your logic to check shown label... 
    int currentVisiblePage = (scrollView.contentOffset.y / self.view.frame.size.height) + 1;
}
Salman Zaidi
  • 9,342
  • 12
  • 44
  • 61
  • if you want to know about when your page is completely shown, then remove '+ 1' from equation – Salman Zaidi Nov 20 '13 at 05:32
  • Salman, When i scrolling the labels inside scrollview, how to position label to display completely. I mean some times half portion of pervious label and half portion of current label is visible.(Eg: When i scroll from 1 to 7, some times half portion of 6 and half portion of 7 is visible) – Prasad Dec 02 '13 at 07:04
  • enable pagging of scrollview.. when you scroll while pagging is on in scrollview. whole page gets scrolled down or up :-) – Salman Zaidi Dec 02 '13 at 07:50
0

if you just want a single scrollable label, would be to use UITextView instead (reference). Disable editing, and you get a scrollable label.

(Taken almost verbatim from: how to add a scroll function to a UILabel)

For more detail:

UILabel inside of UIScrollView – programmatically

Sample code

AutoScrollLabel

Community
  • 1
  • 1
Dhaval Bhadania
  • 3,090
  • 1
  • 20
  • 35