zoukankan      html  css  js  c++  java
  • UIPageControl页控制器

    一、基本知识

    #import "ViewController.h"
    @interface ViewController ()<UIScrollViewDelegate>{
        UIScrollView *scrollview;
        UIPageControl *page;
    }

    @end
    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        page = [[UIPageControl alloc]initWithFrame:CGRectMake(20, 150, 200, 30)];
        page.backgroundColor = [UIColor yellowColor];
        page.numberOfPages = 10;//设置页数(多少个点)
        page.currentPage = 0;//设置当前选中页
        NSLog(@"%zi",page.currentPage);//获取当前选中页下标
        page.pageIndicatorTintColor = [UIColor greenColor];//未选中颜色
        page.currentPageIndicatorTintColor = [UIColor redColor];//当前选中的颜色
        [page addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
       
        [self.view addSubview:page];
       
        scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(20, 150, 300, 400)];
        scrollview.contentSize = CGSizeMake(900, 0);
        scrollview.delegate = self;
        scrollview.pagingEnabled = YES;
        [self.view addSubview:scrollview];
       
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 400)];
        view.backgroundColor = [UIColor grayColor];
        [self.view addSubview:view];
       
        UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(300, 0, 300, 400)];
        view1.backgroundColor = [UIColor blackColor];
        [self.view addSubview:view1];
       
        UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(600, 0, 300, 400)];
        view2.backgroundColor = [UIColor yellowColor];
        [self.view addSubview:view2];
       
    }

    -(void)change:(id)pc{
        NSLog(@"%zi",[pc currentPage]);//获取页数
        CGPoint p = {[pc currentPage]*300,0};//
        [scrollview setContentOffset:p animated:YES];//允许动画
       
    }

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        int index =  scrollview.contentOffset.x/scrollview.frame.size.width;
        page.currentPage = index;
    }
  • 相关阅读:
    MongoDB驱动之Linq操作
    连接Access数据库
    ExecutorCompletionService原理具体解释
    Java 构造时成员初始化的陷阱
    activeMQ公布订阅模式中中经常使用工具类
    计算机视觉、图像处理一些先进研究机构
    php循环,die/exit脚本执行控制,文件载入及错误控制
    VCenter中嵌套openstack VM不能ping通外部网络问题解决的方法
    代码保存、配色、公布-总体方案----一段代码的公布
    【iOS开发系列】NSObject方法介绍
  • 原文地址:https://www.cnblogs.com/wxzboke/p/4978409.html
Copyright © 2011-2022 走看看