首页 > 其他 > 详细

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

时间:2014-03-14 17:05:46      阅读:440      评论:0      收藏:0      [点我收藏+]

_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];
    }
    

}

PageControl的小点点随ScrollView滑动而变动代码,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/tanwen1989/p/3600190.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!