博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PageControl的小点点随ScrollView滑动而变动代码
阅读量:4617 次
发布时间:2019-06-09

本文共 1711 字,大约阅读时间需要 5 分钟。

_scrollViewing=[[[UIScrollView alloc]initWithFrame:CGRectMake(0 ,  0, width(_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*kIPhoneWidth, 0) animated:YES];
    }
    else
    {
        [_scrollViewing setContentOffset:CGPointMake(0, 0) animated:YES];
    }
    

}

转载于:https://www.cnblogs.com/tanwen1989/p/3600190.html

你可能感兴趣的文章
Excel导出POI
查看>>
兼容性
查看>>
自动执行sftp命令的脚本
查看>>
转 Merkle Tree(默克尔树)算法解析
查看>>
网络编程基础之socket编程
查看>>
各种浏览器的user-agent和
查看>>
Restful levels
查看>>
Phonegap移动开发:布局总结(一) 全局
查看>>
Java 变参函数的实现
查看>>
nrf51 SDK自带例程的解读
查看>>
SESSION技术
查看>>
数据结构(五)之直接插入排序
查看>>
SQL函数——LENGTH()和LENGTHB()
查看>>
vim - manual -个人笔记
查看>>
详解Javascript中prototype属性(推荐)
查看>>
angularjs实现首页轮播图
查看>>
Git 对象 和checkout 和stash的笔记
查看>>
团队项目总结2-服务器通信模型和顺序图
查看>>
hdu 1085 Holding Bin-Laden Captive!
查看>>
[周记]8.7~8.16
查看>>