开发者

changing the color of a label box if we scroll the scroll view

开发者 https://www.devze.com 2023-02-22 02:55 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消