实现代码:

//
// ViewController.m
// UIpageControl
//
// Created by dllo on 16/3/10.
// Copyright © 2016年 dllo. All rights reserved.
// #import "ViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height @interface ViewController ()<UIScrollViewDelegate> @property (nonatomic, retain)UIScrollView *scrollView;
@property (nonatomic, retain)UIPageControl *pageControl;
@property (nonatomic, retain)UILabel *titleLabel; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor yellowColor];
self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(, , , )];
self.pageControl.backgroundColor = [UIColor redColor];
[self.view addSubview:self.pageControl];
[self.pageControl release];
self.pageControl.numberOfPages = ;
self.pageControl.pageIndicatorTintColor = [UIColor grayColor];
self.pageControl.currentPageIndicatorTintColor = [UIColor cyanColor];
[self.pageControl addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged]; self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(, ,WIDTH, )];
[self.view addSubview:self.scrollView];
[self.scrollView release];
self.scrollView.contentSize = CGSizeMake(WIDTH * , ); for (NSInteger i = ; i < ; i++) {
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH * i + WIDTH , , WIDTH, HEIGHT)];
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"h%ld.jpeg", i]];
[self.scrollView addSubview:imageView];
}
UIImageView *firstImageView = [[UIImageView alloc]initWithFrame:CGRectMake(, , WIDTH, HEIGHT)];
firstImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"h6.jpeg"]];
[self.scrollView addSubview:firstImageView];
[firstImageView release]; UIImageView *lastImageView = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH * , , WIDTH, HEIGHT)];
lastImageView.image = [UIImage imageNamed:@"h0.jpeg"];
[self.scrollView addSubview:lastImageView];
[lastImageView release]; //创建label
self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
[self.view addSubview:self.titleLabel];
[_titleLabel release];
self.titleLabel.backgroundColor = [UIColor grayColor];
[self.titleLabel setTextColor:[UIColor whiteColor]];
self.titleLabel.textAlignment = ;
self.titleLabel.text = @"1 / 7";
self.scrollView.contentOffset = CGPointMake(WIDTH, );
self.scrollView.pagingEnabled = YES;
self.scrollView.delegate = self;
}
- (void)pageAction:(UIPageControl *)page {
NSLog(@"%ld", self.pageControl.currentPage);
// self.scrollView.contentOffset = CGPointMake(WIDTH * page.currentPage + WIDTH, 0);
[self.scrollView setContentOffset:CGPointMake(WIDTH *page.currentPage + WIDTH, ) animated:YES];
[self.titleLabel setText:[NSString stringWithFormat:@"%ld / 7", (NSInteger)(page.currentPage + )]];
}
//滑动结束
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
if (scrollView.contentOffset.x == ) {
scrollView.contentOffset = CGPointMake(WIDTH * , );
}else if(scrollView.contentOffset.x == * WIDTH){
scrollView.contentOffset = CGPointMake(WIDTH , );
} self.pageControl.currentPage = scrollView.contentOffset.x / WIDTH - ;
[self.titleLabel setText:[NSString stringWithFormat:@"%ld / 7", (NSInteger)(self.pageControl.currentPage + )]];
}
- (void)dealloc{
[_scrollView release];
[_pageControl release];
[super dealloc];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

UIScrollView和UIPageController的更多相关文章

  1. 图像和滚动 、 编程规范和Xcode(一)

    1 在界面上以各种模式显示图片 1.1 问题 在ios开发中经常需要展示图片以满足需求和美化界面,本案例将学习如何以代码的方式使用UIImageView视图控件来展示图片,如图-1所示: 图-1 1. ...

  2. 你真的了解UIScrollView吗?

    一:首先查看一下关于UIScrollView的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIScrollView : UIView <NSCoding& ...

  3. 【原】Masonry+UIScrollView的使用注意事项

    [原]Masonry+UIScrollView的使用注意事项 本文转载请注明出处 —— polobymulberry-博客园 1.问题描述 我想实现的使用在一个UIScrollView依次添加三个UI ...

  4. UIScrollView的封装

    UIScrollView的封装 效果 特点 1.用法简单,尺寸大小,随意设置位置 2.可以有多个数据源的数据,可以定制不通的界面(如同上图,一个有文字,一个没有文字) 3.能够实现点击事件 用法 1. ...

  5. UI第十七节——UIScrollView

    // 实例化一个ScrollView    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen main ...

  6. UI控件(UIScrollView)

    @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //创建一个scrollview UIScrollV ...

  7. UIScrollView的delaysContentTouches与canCencelContentTouches属性

    UIScrollView有一个BOOL类型的tracking属性,用来返回用户是否已经触及内容并打算开始滚动,我们从这个属性开始探究UIScrollView的工作原理: 当手指触摸到UIScrollV ...

  8. iOS 视图:重绘与UIScrollView(内容根据iOS编程编写)

    我们继续之前的 Hypnosister 应用,当用户开始触摸的时候,圆形的颜色会改变. 首先,在 JXHypnosisView 头文件中声明一个属性,用来表示圆形的颜色. #import " ...

  9. 学习笔记之-------UIScrollView 基本用法 代理使用

    //contentSize.contentInset和contentOffset 是 scrollView三个基本的属性. // 滚动 self.ScrollView.contentSize =sel ...

随机推荐

  1. AFHTTPClient的异步回调模式

    以前第一个版本,ios的http都用的同步模式,在很多地方会导致线程阻塞,自己开发了一个简易的AFHTTPClient的异步回调模式. 回调的protocol: @protocol MyAFNetwo ...

  2. Linux Commands intro1

    $((expression)) echo $(2+2) :wrong echo $((2+2))  : right echo Front-{A,B,C}-Back Front-A-Back Front ...

  3. 初始化 Ubuntu Trusty 14.04

    1. 软件源 sudo vim /etc/apt/source.list # 将软件源改为 sohu 的 deb http://mirrors.sohu.com/ubuntu/ trusty main ...

  4. UESTC 887 方伯伯的儿童节 --树形DP

    定义: 1.dp[u][1]表示u这个点设立糖果发放点且u这棵子树满足条件时的最少糖果点数 2.dp[u][0]表示u这个点不设立发放点且u这棵子树满足条件时的最少糖果点数 设v1,v2……vn为u的 ...

  5. 树形DP求树的重心 --SGU 134

    令一个点的属性值为:去除这个点以及与这个点相连的所有边后得到的连通分量的节点数的最大值. 则树的重心定义为:一个点,这个点的属性值在所有点中是最小的. SGU 134 即要找出所有的重心,并且找出重心 ...

  6. java 15-10 List的三个子类的特点

    List:(面试题List的子类特点) ArrayList: 底层数据结构是数组,查询快,增删慢. 线程不安全,效率高. Vector: 底层数据结构是数组,查询快,增删慢. 线程安全,效率低. Li ...

  7. GitHub入门之一:使用github下载项目

    git作为目前比较流行的版本控制系统,被各个互联网公司广泛使用着.目前国外的网站有GitHub,国内的有CSDN和OSCHINA的git. 使用git可以很方便地进行多人协作和版本控制.作为一个入门小 ...

  8. 查询各个商品分类中各有多少商品的SQL语句

    SELECT goods_category_id ,count(*) FROM `sw_goods` group by goods_category_id

  9. WPF - MVVM - 如何将ComboBox的Selectchange事件binding到ViewModel

    转:http://www.cnblogs.com/mantian/p/3713524.html 将所有的事件,属性,都映射到ViewModel中.好处多多,以后开发尽量用这种模式. 解决方法: 使用S ...

  10. FusionCharts或其它flash的div图层总是浮在最上层? (转)

    div的图层由div的style中的z-index来决定,z-index是层垂直屏幕的坐标,0最小,越大的话位置越靠上. 由于FusionCharts的图表都放在div中,如果页面还有其他的div,将 ...