iOS UI06_UIPageControl
2015-08-06 15:04
471 查看
// // MainViewController.m // UI06_UIPageControl // // Created by dllo on 15/8/5. // Copyright (c) 2015年 zhozhicheng. All rights reserved. // #import "MainViewController.h" #define WIDTH self.view.frame.size.width #define HEIGHT self.view.frame.size.height @interface MainViewController ()<UIScrollViewDelegate> @property(nonatomic,retain)UIScrollView *scrollView; @property(nonatomic,retain)UIImageView *imageView; @end @implementation MainViewController -(void)dealloc { [_scrollView release]; [_imageView release]; [super dealloc]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; self.scrollView.backgroundColor=[UIColor yellowColor]; [self.view addSubview:self.scrollView]; [self.scrollView release]; self.scrollView.contentSize=CGSizeMake(13 * WIDTH, HEIGHT-100); self.scrollView.pagingEnabled=YES; for (NSInteger i=0; i<13; i++) { NSString *picName=[NSString stringWithFormat:@"cymbal_%02ld.jpg",i]; self.imageView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:picName]]; self.imageView.frame=CGRectMake(i * WIDTH, 0, WIDTH, HEIGHT-100); [self.scrollView addSubview:self.imageView]; [self.imageView release]; } self.scrollView.contentOffset=CGPointMake(0, 0); self.scrollView.bounces=NO; self.scrollView.showsHorizontalScrollIndicator=NO; self.scrollView.showsVerticalScrollIndicator=NO; self.scrollView.delegate=self; UIPageControl *page =[[UIPageControl alloc] initWithFrame:CGRectMake(100, 580, 200, 40)]; page.backgroundColor=[UIColor redColor]; [self.view addSubview:page]; [page release]; //图片个数和点的个数相同 page.numberOfPages =13; //点的背景颜色 page.pageIndicatorTintColor=[UIColor blackColor]; //被选中的点的颜色 page.currentPageIndicatorTintColor=[UIColor whiteColor]; //添加点击方法 [page addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged]; page.tag=1000; //scrollView缩放 //缩放的比例 self.scrollView.maximumZoomScale=2; self.scrollView.minimumZoomScale=0.5; //原始缩放比例 self.scrollView.zoomScale=1; } #pragma mark 缩放协议方法 -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return [scrollView.subviews firstObject]; } -(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]; } // -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { //滑动图片,让圆点跟着一起动 UIPageControl *page=(UIPageControl *)[self.view viewWithTag:1000]; page.currentPage = self.scrollView.contentOffset.x / WIDTH; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
相关文章推荐
- iOS开发系列--UITableView全面解析
- iOS UI06_UIScorollView
- [LeetCode] Unique Binary Search Trees
- js 获取select标签的value 和 text
- UITextFild功能大全
- Blueprint的环境管理器
- Android UI学习之ListView(使用ArrayAdapter和SimpleAdapter)
- 社工数据搜索引擎搭建 - Build Social Engineer Evildata Search Engine
- OS开发UI篇—CAlayer(自定义layer)
- UIView的常用属性
- HDU1.3.7 Crixalis's Equipment
- ffmpeg streaming guid
- android ui组件
- Implement Queue using Stacks
- duilib
- iOS - UIScrollView控件实现图片缩放功能(还需补充代码)
- Yahoo.Yui.Compressor 压缩js文件
- hdoj 1242 Rescue
- iOS - UIScrollView控件 常用属性、注意点
- C# system.web.ui生成html