实现代码:

//
// 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. 小结getBytes()默认编码导致的xml字符串中出现乱码

    遇到乱码第一印象想到的是如何统一编码,很少注意到这期间穿插的某些过程也是一大隐患.. sae上部署了一个spring写的微信小程序,手机总关注测试号点击菜单得到的文本消息却是乱码.. 聚焦发送消息的部 ...

  2. git一些常用设置

    用法:git config [选项] 配置文件位置    --global              使用全局配置文件    --system              使用系统级配置文件    -- ...

  3. 谈MongoDB读取连接超时的异常

    今天在现场的哥们发来异常,让我解决,错误信息如下: HTTP Status 500 - Read operation to server 192.168.1.110:20001 failed on d ...

  4. WEB安全--CSRF防御

    CSRF漏洞防御主要可以从三个层面进行,即服务端的防御.用户端的防御和安全设备的防御. 服务端的防御 目前服务器端防御CSRF攻击主要有5种策略(我知道的就这么多):验证HTTP Referer字段, ...

  5. openfire+asmack搭建的安卓即时通讯(一) 15.4.7

    最进开始做一些android的项目,除了一个新闻客户端的搭建,还需要一个实现一个即时通讯的功能,参考了很多大神成型的实例,了解到operfire+asmack是搭建简易即时通讯比较方便,所以就写了这篇 ...

  6. 该如何认识ZBrush中的2.5D绘画

    ZBrush不仅对3D行业进行了改革.让艺术家感到无约束自由创作的3D设计,同时它还是一个强大的绘画程序!基于强大的Pixol功能,ZBrush®将数字绘画提升到一个新的层次.如下图所示,插画功能主要 ...

  7. [cocos2dx]2.2到3.1(3.0)升级帮助

    摘要: cocos2dx 是一款优秀的多平台,专为2D游戏设计的引擎. 在活跃的开源社区的推进下, 越发稳定和强大. 2.x -> 3.x的更新幅度很大, 性能的提升和功能的丰富也非常明显. 但 ...

  8. Python创建Cocos2d-x 2.2方法

    把创建项目做成一个批处理,当创建项目时可以省时省力很多. 操作步骤 1.在 E:\cocos2d-x-2.2.1\tools\project-creator 目录下创建 create_project. ...

  9. 【mybatis】1、入门CURD基本操作(环境搭建)

    #1.基本环境 环境 版本 jdk 1.7.0_10 ide eclipse-jee-luna-SR2-win32-x86_64 maven 3.3.3 mybatis 3.2.7 mysql 5.1 ...

  10. You are note Hk

    直接打开是forbidden  最后一句话提示 于是改包 第二次还是修改包 Mozilla/5.0 (MSIE 7.0; Windows NT 6.0;.NET CLR 9.9)