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