首页 > 其他 > 详细

UIPageControl

时间:2016-02-16 18:26:42      阅读:219      评论:0      收藏:0      [点我收藏+]
//
//  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

UIPageControl

原文:http://www.cnblogs.com/iQingYang/p/5193216.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!