I'm trying to make an app in which there's a scrollview with frame and content size set from storyboard. i have inserted a label and both scrollview and uilabel have iboutlet created. i want to change text of uilabel each time i scroll with paging. content is saved in a nsmutable array as string. there's only single uilabel, and i wanna reuse it with content from array in every page of scroll view. please help..
0
votes
1 Answers
0
votes
I think you need to use one of the method of UIScrollViewDelegate
like scrollViewDidEndDecelerating:
in this you can change the text of label and also the frame of the label to show it in visible rect of scrollview
- (void)scrollViewDidEndDecelerating:(UIScrollView *)ascrollView
{
if(lastContentOffset < ascrollView.contentOffset.x)
{
if(index-2 >= 0)
{
[ascrollView addSubview:[thumbs objectAtIndex:index-2]];
index-=1;
//change label text using the index and also it's frame's origin.x
NSLog(@"Direction Right Index %d",index);
}
}
else if(lastContentOffset > ascrollView.contentOffset.x)
{
if(index+2 < [thumbs count])
{
[ascrollView addSubview:[thumbs objectAtIndex:index+2]];
index+=1;
//change label text using the index and also it's frame's origin.x
NSLog(@"Direction Left Index %d",index);
}
}
NSLog(@"ScrollViewDidScroll is called");
lastContentOffset = ascrollView.contentOffset.x;
}
here the lastContentOffset
is float variable which holds the current visible frame's x of the scrollview
in .m file declare two ivars below all the @synthesize as
NSMutableArray *arr;
& float lastContentOffset;
then when you fill your scrollView just assign it's frame's origin.x to the lastContentOffset
and then use the arr
to change the text of label