• UIPageControl


    //
    //  ViewController.m
    //  UIPageControl 01
    //
    //  Created by cqy on 16/2/15.
    //  Copyright © 2016年 程清杨. All rights reserved.
    //

    #import "ViewController.h"
    #define WIDTH   [[UIScreen mainScreen] bounds].size.width
    #define HEIGHT   [[UIScreen mainScreen] bounds].size.height
    @interface ViewController ()<UIScrollViewDelegate>
    {   UIScrollView *scroll;
        UIPageControl *page;
    }

    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
       
        UIImageView *imgview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]];
       
        imgview.frame = CGRectMake(0, 0, 200, 200);
        UIImageView *imgview1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2"]];
        imgview1.frame = CGRectMake(WIDTH, 0, 200, 200);
       
        UIImageView *imgview2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"3"]];
        imgview2.frame = CGRectMake(2*WIDTH, 00, 200, 200);
       
        scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,30, WIDTH, 200)];
        [scroll addSubview:imgview];
        [scroll addSubview:imgview1];
        [scroll addSubview:imgview2];
       
        scroll.backgroundColor = [UIColor greenColor];
        scroll.contentSize = CGSizeMake(2*WIDTH, 200);
        scroll.delegate = self;
        scroll.pagingEnabled = YES;
        scroll.scrollEnabled = YES;
       
        [self.view addSubview:scroll];
       
        page = [[UIPageControl alloc] initWithFrame:CGRectMake(70, 350, 200, 40)];
       
        page.backgroundColor = [UIColor whiteColor];
        page.numberOfPages = 3;//设置页数(多少个点)
        page.currentPage = 2;//设置当前选中页
        NSLog(@"--%zi--",page.currentPage);//获取当前选中页下标
        page.pageIndicatorTintColor = [UIColor grayColor];//未选中颜色
        page.currentPageIndicatorTintColor = [UIColor greenColor];//选中颜色
        [page addTarget:self action:@selector(trigger:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:page];
       
           // Do any additional setup after loading the view, typically from a nib.
    }
    -(void)trigger: (UIPageControl *) tri{
        NSLog(@"-%zi-",[page currentPage]);
        CGPoint p = {[page currentPage]*300,0};
        [scroll setContentOffset:p animated:YES];
        NSLog(@"trigger...");
    }
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    @end
  • 相关阅读:
    关于敏捷开发的一些思考。
    【转】浅谈程序猿的职业规划,看你如何决定自己的未来吧。
    Individual Project
    homework_06 围棋程序改进
    homework 08_2 C++11新特性作业之二
    homework_08
    软件工程个人作业——Agile Software Development读后感
    附加题——软件工程之结对编程
    软件工程——PairProject
    软件工程第一次个人项目——词频统计by11061153柴泽华
  • 原文地址:https://www.cnblogs.com/iQingYang/p/5193216.html
Copyright © 2020-2023  润新知