#import "ViewController.h"

#import "LazyScrollView.h"

@interface ViewController ()<UIScrollViewDelegate>

{

UIPageControl *pageControl;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

UIScrollView *scroView = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];

scroView.contentSize = CGSizeMake(CGRectGetWidth([UIScreen mainScreen] .bounds)*10, 0);

scroView.delegate = self;// ?

[self.view addSubview:scroView];

CGFloat width = CGRectGetWidth([UIScreen mainScreen].bounds);

for (int i=0; i<10; i++) {

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(width*i, 0, width, CGRectGetHeight([UIScreen mainScreen].bounds))];

view.backgroundColor = [UIColor purpleColor];

view.layer.borderWidth = 4;// ?

view.alpha = 0.7;

view.layer.borderColor = [UIColor whiteColor].CGColor;

[scroView addSubview:view];

}

//  UIPageControl页面控制的控件

/*

可以通过UIPageControl 来确定  当前视图在哪一页

1、一共有多少页  numberOfPages

2、当前页面   currentPage

UIPageControl ->.....

*/

pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, 300, CGRectGetWidth([UIScreen mainScreen].bounds), 30)];

//总共有多少页

pageControl.numberOfPages = 10;

//默认的当前页面

pageControl.currentPage = 0;

//设置页面控制的轨道颜色

pageControl.pageIndicatorTintColor = [UIColor brownColor];

//设置当前页面 点 的颜色

pageControl.currentPageIndicatorTintColor = [UIColor lightGrayColor];

//当一个页面的时候隐藏点点点

pageControl.hidesForSinglePage = YES;

[self.view addSubview:pageControl];

//如果默认页面  不是第一个页面  可以通过contentOffset  去设置偏移到哪一个位置

scroView.contentOffset = CGPointMake(CGRectGetWidth([UIScreen mainScreen].bounds)*pageControl.currentPage, 0);

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

NSInteger curIndex = scrollView.contentOffset.x/CGRectGetWidth(scrollView.frame);

NSLog(@"%ld",curIndex);

pageControl.currentPage = curIndex;

}

最新文章

  1. Oracle --&gt; Vertica 数据类型转换规则
  2. 【Codeforces235C】Cyclical Quest 后缀自动机
  3. tachyon of zybo cluster
  4. 菜菜CPP日记
  5. JS基础回顾,小练习(判断数组,以及函数)
  6. IDEA操作GIT说明
  7. phpcms v9后台多表查询分页代码
  8. 动态用javascript来修改单选框性别
  9. CodeForces 371D. Vessels
  10. DOM操作-动态创建网页元素
  11. Android Studio文件目录介绍
  12. uva11059(最大乘积)
  13. Linux入门篇(三)——文件与目录
  14. 2D变形transform的translate和rotate
  15. {python--GIL锁}一 介绍 二 GIL介绍 三 GIL与Lock 四 GIL与多线程 五 多线程性能测试
  16. python导外部包
  17. ThinkPHP3.2设置异常页面404跳转页面
  18. Websphere中获取项目下.properties路径
  19. Scrum立会报告+燃尽图(Beta阶段第二周第一次)
  20. bootstrap基础学习四篇

热门文章

  1. Cesium专栏-百度地图加载(附源码下载)
  2. javaWeb实现验证码--代码超简单
  3. 4.Redux学习4----react-redux
  4. python-基础r/R、b、u/U含义
  5. 让 Lua 访问数据库
  6. Java中数组与集合的相互转换
  7. Orcle如何获取当前时间
  8. Spring Boot 2.X(十三):邮件服务
  9. 在 ASP.NET Core 中启用跨域请求(CORS)
  10. xshell破解