PageControl的小点点随ScrollView滑动而变动代码

_scrollViewing=[[[UIScrollView alloc]initWithFrame:CGRectMake(0 ,  0width(_specialView),  height(_specialView))] autorelease];
    
_scrollViewing.backgroundColor=[UIColor grayColor];
    
_scrollViewing.pagingEnabled=YES;
    
_scrollViewing.contentSize=CGSizeMake(_scrollViewing.frame.size.width * 3_scrollViewing.frame.size.height);
    
_scrollViewing.showsVerticalScrollIndicator=NO;
    
_scrollViewing.showsHorizontalScrollIndicator=NO;
    
_scrollViewing.delegate=self;
    
_scrollViewing.userInteractionEnabled = YES;//
    
_scrollViewing.tag = kDailyScrollViewTag;//
    
_scrollViewing.pagingEnabled = YES;//

    [_specialView addSubview:_scrollViewing];
 
 

_pageControl=[[[UIPageControl alloc]initWithFrame:CGRectMake(260 , 140 , 60 ,10)] autorelease];
    
_pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    
_pageControl.numberOfPages=3;
    
_pageControl.currentPage = 0;
    [
_pageControl addTarget:self action:@selector(pageControlValueChanged:) forControlEvents:UIControlEventTouchUpInside];

    [_specialView addSubview:_pageControl];
 
//关键点

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
//PageControl的小点点随ScrollView滑动而变动
    
CGFloat pagewidth = _scrollViewing.frame.size.width;
    
int page = floor((_scrollViewing.contentOffset.x - pagewidth/(3+2))/pagewidth)+1;
    
_pageControl.currentPage = page;
    
}

 

//分页控制器方法
-(
void)pageControlValueChanged:(UIPageControl *)pageControl
{
    
    
int currentPage=(int)pageControl.currentPage;
    
_scrollViewing=(UIScrollView *)[self.view viewWithTag:kDailyScrollViewTag];
    
if (currentPage>0)
    {
        [
_scrollViewing setContentOffset:CGPointMake(currentPage*kIPhoneWidth0animated:YES];
    }
    
else
    {
        [
_scrollViewing setContentOffset:CGPointMake(00animated:YES];
    }
    

}
posted @ 2014-03-14 11:35  曈曈7添  阅读(216)  评论(0)    收藏  举报