zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    sigaction函数解析
    实战Nginx与PHP(FastCGI)的安装、配置与优化
    Linux下Nginx+PHP 简单安装配置
    Nginx安装配置PHP(FastCGI)环境的教程
    Linux上配置Nginx+PHP5(FastCGI)
    @JoinTable和@JoinColumn
    Spring Data JPA 之 一对一,一对多,多对多 关系映射
    MyChrome制作Chrome浏览器便携版
    注解@CrossOrigin解决跨域问题
    MySQL查看表结构及查看建表语句
  • 原文地址:https://www.cnblogs.com/iQingYang/p/5193216.html
Copyright © 2011-2022 走看看