码迷,mamicode.com
首页 > 其他好文 > 详细

UIPageControl

时间:2016-02-23 19:05:11      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

UIPageControl控件在程序中出现的?较频繁,尤其在和 UIScrollView(滚动视图)配合来显??量数据时,会使?它来控制 UIScrollView的翻页。在滚动ScrollView时可通过PageControll中的 ??点来观察当前页?的位置,也可通过点击PageControll中的? ?点来滚动到指定的页?。
 
numberOfPages //指定页?个数(即点的个数)
currentPage //指定pageControl的值(即选中的点)
    addTarget:action:forControlEvents: //添加事件
    注意:controlEvent为UIControlEventValueChanged
    原因:分页本质是通过数据管理分页,所以使?valueChanged属性来触发事件,即数组下标变化
 
 
创建:
 
UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(100, self.view.frame.size.height - 100, self.view.frame.size.width - 200, 40)];
   
    //设置pageControl的?数
    pageControl.numberOfPages = 3;
   
    //设置当前? 默认为0(第??)
    pageControl.currentPage = 0;
   
    //点的颜色
    pageControl.pageIndicatorTintColor = [UIColor orangeColor];
    pageControl.backgroundColor = [UIColor grayColor];
    
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.JPG"]];
    image.tag = 102;
    image.frame = [[UIScreen mainScreen] bounds];
    [self.view addSubview:image];
    [image release];
 
     //添加事件
    [pageControl addTarget:self action:@selector(pageChange:) forControlEvents:UIControlEventValueChanged];
  
    [self.view addSubview:pageControl];
    [pageControl release];
 
 
 
      - (void)pageChange:(UIPageControl *)page {
    UIImageView *newImage = (UIImageView *)[self.view viewWithTag:102];
    newImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.JPG",page.currentPage + 1]];
}

UIPageControl

标签:

原文地址:http://www.cnblogs.com/Walking-Jin/p/5210850.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!