UIPageControl
2015-08-16 09:50
369 查看
UIPageControl配合UIScrollView使用
self.scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame]; self.scrollView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:self.scrollView]; self.scrollView.delegate = self; [_scrollView release]; self.scrollView.showsHorizontalScrollIndicator = NO; self.scrollView.showsVerticalScrollIndicator = NO; self.scrollView.contentSize = CGSizeMake(WIDTH * 7, HEIGHT); for (NSInteger i = 1; i < 8; i++) { NSString *picName = [NSString stringWithFormat:@"h%ld.jpeg",i]; UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:picName]]; imageView.frame = CGRectMake(WIDTH * (i - 1), 0, WIDTH, HEIGHT); [self.scrollView addSubview:imageView]; [imageView release]; } self.scrollView.pagingEnabled = YES; UIPageControl *page = [[UIPageControl alloc]initWithFrame:CGRectMake(100, 635, 200, 40)]; [self.view addSubview:page]; //scrollView的缩放 //缩放的比例 self.scrollView.maximumZoomScale = 2; //最小的比例 self.scrollView.minimumZoomScale = 0.5; //原始的缩放比例 self.scrollView.zoomScale = 1; //page.backgroundColor = [UIColor blackColor]; page.tag = 1000; [page release]; //图片个数和点的个数相同 page.numberOfPages = 7; //点的背景颜色 page.pageIndicatorTintColor = [UIColor grayColor]; //被选中的圆点的背景颜色 page.currentPageIndicatorTintColor = [UIColor purpleColor]; //给它添加一个点击的方法 [page addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged]; self.LTview = [[LTView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 300)]; self.LTview.lable.backgroundColor = [UIColor blackColor]; [self.view addSubview:self.LTview]; [self.LTview release]; //当scrollView停止滑动时用偏移量的值除以宽度赋值给page,使page与滚动的页面相匹配 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ NSInteger i = scrollView.contentOffset.x / WIDTH; UIPageControl *page = (UIPageControl *)[self.view viewWithTag:1000]; page.currentPage = i; } -(void)pageAction:(UIPageControl *)page{ //点的个数从第0张开始 NSLog(@"%ld",page.currentPage); //触发事件进行图片的切换 //self.scrollView.contentOffset = CGPointMake(WIDTH * page.currentPage, 0); [self.scrollView setContentOffset:CGPointMake(WIDTH * page.currentPage, 0) animated:YES]; } #pragma mark 专门用来缩放的协议方法 -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ return [scrollView.subviews firstObject]; }
相关文章推荐
- IOS之UIAlertController
- POJ 2533 Longest Ordered Subsequence
- Havok_2014-1-0_Pc_Xs_User_Guide(2.5.1-Character Control)
- 子线程更新UI的方法与解析!
- Android基础UI篇------TextView及其子类
- Codeforces Round #316 (Div. 2) D. Tree Requests dfs_clock,二分
- 从UE4开始蜕变
- POJ - 1904 King's Quest(强连通分量+二分图匹配)
- poi Build path 配置,顺序问题
- 解决PHPCMS使用ueditor时缩略图上传问题
- UEditor使用技巧(2):自定义样式
- 百度Ueditor编辑器的Html模式自动替换样式的解决方法
- 空中网面试题二SynchronousQueue
- poj 1947 Rebuilding Roads 树形dp
- UIButton和UIImageView的区别一
- iOS开发UI篇—核心动画(UIView封装动画)
- pat(A) 1007. Maximum Subsequence Sum(和最大子段)
- HDU 1005.Number Sequence【很多问题是不能直接求的】【8月15】
- codeforces#FF DIV2C题DZY Loves Sequences(DP)
- HDU 2227 Find the nondecreasing subsequences