//
// ViewController.h
// UI2_ScrollView&UIPageControl
//
// Created by zhangxueming on 15/7/10.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIScrollViewDelegate> @end
//
// ViewController.m
// UI2_ScrollView&UIPageControl
//
// Created by zhangxueming on 15/7/10.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h" #define ClipsBundleWidth ((self.view.frame.size.width-300)/2) @interface ViewController ()
{
UIScrollView *_scrollView;
UIPageControl *_pageControl;//页码
NSInteger _currentIndex;//记录当前显示的页码
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(ClipsBundleWidth, 64, 300, 450)];
_scrollView.contentSize = CGSizeMake(300*6, 450);
_scrollView.pagingEnabled = YES; for (int i=0; i<6; i++) {
NSString *imageName = [NSString stringWithFormat:@"%d",i];
NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(300*i, 0, 300, 450)];
imageView.image = [UIImage imageWithContentsOfFile:path];
[_scrollView addSubview:imageView];
} _pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(ClipsBundleWidth, 64+450, 300, 30)];
_pageControl.numberOfPages = 6;
_currentIndex = 0;
_pageControl.currentPage = _currentIndex;
_pageControl.backgroundColor = [UIColor blackColor]; [self.view addSubview:_pageControl]; UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
backBtn.frame = CGRectMake(50, 64+450+30, (self.view.frame.size.width-100)/2, 30);
[backBtn setTitle:@"back" forState:UIControlStateNormal];
backBtn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[backBtn addTarget:self action:@selector(backBtnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backBtn]; UIButton *forwardBtn = [UIButton buttonWithType:UIButtonTypeSystem];
forwardBtn.frame = CGRectMake(50+(self.view.frame.size.width-100)/2, 64+450+30, (self.view.frame.size.width-100)/2, 30);
[forwardBtn setTitle:@"forward" forState:UIControlStateNormal];
forwardBtn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[forwardBtn addTarget:self action:@selector(forwardBtnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:forwardBtn]; //代理
_scrollView.delegate = self; [self.view addSubview:_scrollView]; } - (void)backBtnClicked
{
_currentIndex--;
if (_currentIndex>=0) {
CGPoint point = CGPointMake(_currentIndex*300 , _scrollView.contentOffset.y);
[_scrollView setContentOffset:point animated:YES];
_pageControl.currentPage = _currentIndex;
}
else
{
_currentIndex = 5;
CGPoint point = CGPointMake(_currentIndex*300 , _scrollView.contentOffset.y);
[_scrollView setContentOffset:point animated:YES];
_pageControl.currentPage = _currentIndex;
}
} - (void)forwardBtnClicked
{
_currentIndex++;
if (_currentIndex<=5) {
CGPoint point = CGPointMake(_currentIndex*300, _scrollView.contentOffset.y);
[_scrollView setContentOffset:point animated:YES];
_pageControl.currentPage = _currentIndex;
}
else
{
_currentIndex = 5;
}
} - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
_currentIndex = scrollView.contentOffset.x/300;
_pageControl.currentPage = _currentIndex;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

UI2_ScrollView&UIPageControl的更多相关文章

  1. iOS-OC-基本控件之UIPageControl

    UIPageControl(页面控制器,就是桌面的那些小点点,每个点代表一个界面) 父类是 UIControl. iOS开发中常用的基本控件,主要和UIScrollView一起使用,比较常用的就是有些 ...

  2. UIScrollView,UIPageControl,UIImageView 实现图片轮播的效果

    上一篇博客介绍了如何将XCode创立的项目提交到Git版本控制,这次就直接做一个图片轮播的展示demo,刚好可以把UIScrollView.UIPageControl.UIImageView这三个控件 ...

  3. iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults

    首先创建一个引导图的控制器类 UserGuideViewController.h和UserGuideViewController.m #import <UIKit/UIKit.h> #im ...

  4. UIscrollView和UIPageControl的循环滚动

    因为昨天在网上找了很久,很多只能实现向右滚动,而且一张图一个imageview ,感觉工作量很可怕啊 ,  下面的例子就是不论你多少图 , 只和我代码里面的几个数值有关,  只需要修改分页和循环i的最 ...

  5. iOS-UIScrollView和UIPageControl的综合实力,滚动图,轮播图

    本代码主要实现图片之间的切换 目录结构 代码 ViewController.m文件 #import "ViewController.h" @interface ViewContro ...

  6. iOS-设置UIPageControl 显示图片

    UIPageControl 的默认样式是几个小圆点,系统没有提供属性供我们自定义这几个小圆点的样式,不过我们依然可以使用KVC来自定义PageControl的显示样式 UIPageControl *p ...

  7. scrollView实现基础中心点缩放及与UIPageControl结合使用

    一般来说scrollView与UIPageControl都是结合使用,因为在使用滚动视图的时候 ,使用UIPageControl,用户可以 清楚 的明白显示的内容有多少页,如果 没有的话,总不能让用户 ...

  8. 自定义UIPageControl,可设置任意图片image。

    [self.pageControl setValue:[UIImage imageNamed:@"选中图片名称"] forKeyPath:@"_currentPageIm ...

  9. UIPageControl页控制器

    一.基本知识 #import "ViewController.h"@interface ViewController ()<UIScrollViewDelegate>{ ...

随机推荐

  1. [Node.js] Broswerify -- 1

    Browserify is a tool that brings node.js style development to the browser. The thing you can see on ...

  2. mysql博客

    http://blog.csdn.net/mchdba/article/details/9190771 本帖最后由 mchdba 于 2014-2-10 17:15 编辑 公司招聘MySQL DBA, ...

  3. Docker大行其道—镜像

    导读 作为Docker三大核心概念之一,Docker镜像(Docker Image)是一个面向Docker引擎的只读模板,包含文件系统.实际上每个Docker镜像包含一个独立的运行环境,如一个镜像包含 ...

  4. Plugin with data access

    In this tutorial I'll be using the nopCommerce plugin architecture to implement a product view track ...

  5. 精品教程--IOS零基础开发环境搭建

    下载源码 技术要点: 1. 启动XCODE开始开发 2. IOS项目文件结构分析 3. 添加视图label组件 4. 程序的入口以及启动流程 5. 源码详细的中文注释 ...... 详细介绍: 1. ...

  6. [置顶] HashMap HashTable HashSet区别剖析

    HashMap.HashSet.HashTable之间的区别是Java程序员的一个常见面试题目,在此仅以此博客记录,并深入源代码进行分析: 在分析之前,先将其区别列于下面 1:HashSet底层采用的 ...

  7. Jquery zTree结合Asp.net实现异步加载数据

    zTree结合Asp.net实现异步加载数据 实现简单操作 zTree 下载 api 访问 :http://www.ztree.me/v3/main.php 例子中用到json数据转化 newtons ...

  8. 小白日记51:kali渗透测试之Web渗透-WebShell(中国菜刀、WeBaCoo、Weevely)

    webshell 本质:<?php echo shell_exec($_GET['cmd']);?> windows平台 中国菜刀官网:胖客户端程序,国产中比较优秀的webshell,适用 ...

  9. IOS 应用 退出的一个小方法

    AppDelegate * app=(AppDelegate *)[[UIApplication sharedApplication]delegate]; UIWindow *window = app ...

  10. Java基础知识强化之IO流笔记74:NIO之 Buffer

    Java NIO中的Buffer用于和NIO通道进行交互.如你所知,数据是从通道读入缓冲区,从缓冲区写入到通道中的. 缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存.这块内存被包装成NIO ...