zoukankan      html  css  js  c++  java
  • UIPageControl

    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]];
    }
  • 相关阅读:
    TCP的三次握手与四次挥手理解及面试题(很全面)
    python解释器锁的理解
    Flask的基本使用、四剑客和配置文件
    Django cache缓存
    xadmin后台管理
    cookies与session
    Java stream流
    Java IO流
    springboot配置文件加载顺序与一些常用配置
    OAuth2.0开放授权
  • 原文地址:https://www.cnblogs.com/Walking-Jin/p/5210850.html
Copyright © 2011-2022 走看看