i have 4 label box 开发者_Go百科and i have a UIscrollview in that i have 4 pages.if we scroll the scroll view manually(by drag) the color of the label box have to change according to the page number. any hits to do this.
UIScrollView *scroll = [[UIScrollView alloc]initWithFrame: CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 4;
float j=0;
for (int i = 0; i < numberOfViews; i++) {
CGFloat yOrigin = i * self.view.frame.size.width;
printf("%f\n",yOrigin);
UIView *scrollview = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
scrollview.backgroundColor = [UIColor cyanColor];
[scroll addSubview:scrollview];
[scrollview release];
j=j+0.2;
}
Set the UIScrollViewDelegate on your scrollview (most likely to self).
scrollView.delegate=self
Then implement the following on your delegate class
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {...}
Then within that delegate function have a look at the scrollview.contentOffset property. This will tell you what the current position (by way of a CGPoint) of the top-left hand side of your scrollview. Use this CGPoint to determine how much your user has scrolled and when an appropriate amount has been scrolled just change the colour of your UIView/UILabel.
精彩评论