UI控件使用案例<三>
2014-07-17 16:39
281 查看
1. //*********UIScrollview的学习使用********** _scrollView =[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)]; _scrollView.contentSize=CGSizeMake(1280, 100);//UIScrollView的contentSize(内容大小)大小大于本身大小就可以滑动 _scrollView.backgroundColor= [UIColor randomColor]; _scrollView.delegate= self; [self.view addSubview:_scrollView]; UILabel *label1= [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 320, 80)]; UILabel *label2= [[UILabel alloc] initWithFrame:CGRectMake(320, 10, 320, 80)]; UILabel *label3= [[UILabel alloc] initWithFrame:CGRectMake(640, 10, 320, 80)]; UILabel *label4= [[UILabel alloc] initWithFrame:CGRectMake(960, 10, 320, 80)]; label1.backgroundColor= [UIColor randomColor]; label2.backgroundColor= [UIColor randomColor]; label3.backgroundColor= [UIColor randomColor]; label4.backgroundColor= [UIColor randomColor]; [_scrollView addSubview:label1]; [_scrollView addSubview:label2]; [_scrollView addSubview:label3]; [_scrollView addSubview:label4]; [label1 release]; [label2 release]; [label3 release]; [label4 release]; _scrollView.pagingEnabled= YES; _scrollView.tag= 1000; ******************** scrolview.pagingEnabled = YES;//bool类型 一次只滑动一个窗口那么大(一次滑动一页) scrolview.scrollsToTop= YES;//bool类型 点击状态栏 跳转到scrollView 的顶端,会控制离状态栏最近的scrollview scrolview.bounces= NO;//设置是不是回弹bool类型 CGPoint p = CGPointMake(200,200); scrolview.contentOffset= p;//屏幕左上⾓角距离坐标原点的偏移量 scrolview.scrollEnabled= YES;//设定能不能滚屏.设置为no的话就不能滚屏; scrolview.showsHorizontalScrollIndicator= YES;//显示水平位置的滚动条 scrolview.showsVerticalScrollIndicator= YES;//显示垂直方向的滚动条 scrolview.alwaysBounceVertical= YES;//垂直方向是否回弹 scrolview.alwaysBounceHorizontal= YES;//水平方向是否回弹 //缩放*** //scrollView有一个delegate属性 把self设置为代理,去执行缩放等事物 scrolview.delegate= self; scrolview.minimumZoomScale= 0.5;//最大缩放比例 scrolview.maximumZoomScale = 5;//最小缩放比例 [self.viewaddSubview:scrolview]; [scrolviewrelease]; ******** - (UIView *)viewForZoomingInScrollView:(UIScrollView*)scrollView { //这个方法执行后返回一个视图,这个视图可以执行缩放功能 return[scrollView.subviews objectAtIndex:1]; //缩放的过程中会影响contentSize 所以缩放完就不可以移动了 } 2. //**********UIPageControl的学习************ //用于指示当前第几页 通常与UIScrollview结合使用 _pageControl =[[UIPageControl alloc] initWithFrame:CGRectMake(0, 101, 320, 10)]; _pageControl.backgroundColor= [UIColor randomColor]; _pageControl.numberOfPages= 4; _pageControl.currentPage= 0; [_pageControl addTarget:selfaction:@selector(changePage:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:_pageControl]; //+++++++减速结束的时候修改圆点 -(void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView { _pageControl.currentPage= scrollView.contentOffset.x/320; //++++++++++pageControl随着页面滑动而滑动++++++ } - (void)changePage:(UIPageControl*)page { //++++++++++图片页面切换++++++++++ [_scrollView setContentOffset:CGPointMake(320*page.currentPage,0) animated:YES]; NSLog(@"%d",page.currentPage); }
1. //*********UIScrollview的学习使用********** _scrollView =[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)]; _scrollView.contentSize=CGSizeMake(1280, 100);//UIScrollView的contentSize(内容大小)大小大于本身大小就可以滑动 _scrollView.backgroundColor= [UIColor randomColor]; _scrollView.delegate= self; [self.view addSubview:_scrollView]; UILabel *label1= [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 320, 80)]; UILabel *label2= [[UILabel alloc] initWithFrame:CGRectMake(320, 10, 320, 80)]; UILabel *label3= [[UILabel alloc] initWithFrame:CGRectMake(640, 10, 320, 80)]; UILabel *label4= [[UILabel alloc] initWithFrame:CGRectMake(960, 10, 320, 80)]; label1.backgroundColor= [UIColor randomColor]; label2.backgroundColor= [UIColor randomColor]; label3.backgroundColor= [UIColor randomColor]; label4.backgroundColor= [UIColor randomColor]; [_scrollView addSubview:label1]; [_scrollView addSubview:label2]; [_scrollView addSubview:label3]; [_scrollView addSubview:label4]; [label1 release]; [label2 release]; [label3 release]; [label4 release]; _scrollView.pagingEnabled= YES; _scrollView.tag= 1000; ******************** scrolview.pagingEnabled = YES;//bool类型 一次只滑动一个窗口那么大(一次滑动一页) scrolview.scrollsToTop= YES;//bool类型 点击状态栏 跳转到scrollView 的顶端,会控制离状态栏最近的scrollview scrolview.bounces= NO;//设置是不是回弹bool类型 CGPoint p = CGPointMake(200,200); scrolview.contentOffset= p;//屏幕左上⾓角距离坐标原点的偏移量 scrolview.scrollEnabled= YES;//设定能不能滚屏.设置为no的话就不能滚屏; scrolview.showsHorizontalScrollIndicator= YES;//显示水平位置的滚动条 scrolview.showsVerticalScrollIndicator= YES;//显示垂直方向的滚动条 scrolview.alwaysBounceVertical= YES;//垂直方向是否回弹 scrolview.alwaysBounceHorizontal= YES;//水平方向是否回弹 //缩放*** //scrollView有一个delegate属性 把self设置为代理,去执行缩放等事物 scrolview.delegate= self; scrolview.minimumZoomScale= 0.5;//最大缩放比例 scrolview.maximumZoomScale = 5;//最小缩放比例 [self.viewaddSubview:scrolview]; [scrolviewrelease]; ******** - (UIView *)viewForZoomingInScrollView:(UIScrollView*)scrollView { //这个方法执行后返回一个视图,这个视图可以执行缩放功能 return[scrollView.subviews objectAtIndex:1]; //缩放的过程中会影响contentSize 所以缩放完就不可以移动了 } 2. //**********UIPageControl的学习************ //用于指示当前第几页 通常与UIScrollview结合使用 _pageControl =[[UIPageControl alloc] initWithFrame:CGRectMake(0, 101, 320, 10)]; _pageControl.backgroundColor= [UIColor randomColor]; _pageControl.numberOfPages= 4; _pageControl.currentPage= 0; [_pageControl addTarget:selfaction:@selector(changePage:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:_pageControl]; //+++++++减速结束的时候修改圆点 -(void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView { _pageControl.currentPage= scrollView.contentOffset.x/320; //++++++++++pageControl随着页面滑动而滑动++++++ } - (void)changePage:(UIPageControl*)page { //++++++++++图片页面切换++++++++++ [_scrollView setContentOffset:CGPointMake(320*page.currentPage,0) animated:YES]; NSLog(@"%d",page.currentPage); }
1. //*********UIScrollview的学习使用********** _scrollView =[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)]; _scrollView.contentSize=CGSizeMake(1280, 100);//UIScrollView的contentSize(内容大小)大小大于本身大小就可以滑动 _scrollView.backgroundColor= [UIColor randomColor]; _scrollView.delegate= self; [self.view addSubview:_scrollView]; UILabel *label1= [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 320, 80)]; UILabel *label2= [[UILabel alloc] initWithFrame:CGRectMake(320, 10, 320, 80)]; UILabel *label3= [[UILabel alloc] initWithFrame:CGRectMake(640, 10, 320, 80)]; UILabel *label4= [[UILabel alloc] initWithFrame:CGRectMake(960, 10, 320, 80)]; label1.backgroundColor= [UIColor randomColor]; label2.backgroundColor= [UIColor randomColor]; label3.backgroundColor= [UIColor randomColor]; label4.backgroundColor= [UIColor randomColor]; [_scrollView addSubview:label1]; [_scrollView addSubview:label2]; [_scrollView addSubview:label3]; [_scrollView addSubview:label4]; [label1 release]; [label2 release]; [label3 release]; [label4 release]; _scrollView.pagingEnabled= YES; _scrollView.tag= 1000; ******************** scrolview.pagingEnabled = YES;//bool类型 一次只滑动一个窗口那么大(一次滑动一页) scrolview.scrollsToTop= YES;//bool类型 点击状态栏 跳转到scrollView 的顶端,会控制离状态栏最近的scrollview scrolview.bounces= NO;//设置是不是回弹bool类型 CGPoint p = CGPointMake(200,200); scrolview.contentOffset= p;//屏幕左上⾓角距离坐标原点的偏移量 scrolview.scrollEnabled= YES;//设定能不能滚屏.设置为no的话就不能滚屏; scrolview.showsHorizontalScrollIndicator= YES;//显示水平位置的滚动条 scrolview.showsVerticalScrollIndicator= YES;//显示垂直方向的滚动条 scrolview.alwaysBounceVertical= YES;//垂直方向是否回弹 scrolview.alwaysBounceHorizontal= YES;//水平方向是否回弹 //缩放*** //scrollView有一个delegate属性 把self设置为代理,去执行缩放等事物 scrolview.delegate= self; scrolview.minimumZoomScale= 0.5;//最大缩放比例 scrolview.maximumZoomScale = 5;//最小缩放比例 [self.viewaddSubview:scrolview]; [scrolviewrelease]; ******** - (UIView *)viewForZoomingInScrollView:(UIScrollView*)scrollView { //这个方法执行后返回一个视图,这个视图可以执行缩放功能 return[scrollView.subviews objectAtIndex:1]; //缩放的过程中会影响contentSize 所以缩放完就不可以移动了 } 2. //**********UIPageControl的学习************ //用于指示当前第几页 通常与UIScrollview结合使用 _pageControl =[[UIPageControl alloc] initWithFrame:CGRectMake(0, 101, 320, 10)]; _pageControl.backgroundColor= [UIColor randomColor]; _pageControl.numberOfPages= 4; _pageControl.currentPage= 0; [_pageControl addTarget:selfaction:@selector(changePage:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:_pageControl]; //+++++++减速结束的时候修改圆点 -(void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView { _pageControl.currentPage= scrollView.contentOffset.x/320; //++++++++++pageControl随着页面滑动而滑动++++++ } - (void)changePage:(UIPageControl*)page { //++++++++++图片页面切换++++++++++ [_scrollView setContentOffset:CGPointMake(320*page.currentPage,0) animated:YES]; NSLog(@"%d",page.currentPage); }
相关文章推荐
- UI控件使用案例<二>
- UI控件使用案例<一>
- UI控件使用案例<四>
- <Unity UGUI><EasyTouch> 使用EasyTouch, 摇杆在Dynamic模式下,点击UI控件也会弹出的问题解决
- Flex使用<mx:Tree>控件创建树(可添加和删除节点)
- spring3 jsp页面使用<form:form modelAttribute="xxxx" action="xxxx">报错,附连接数据库的spring MVC annotation 案例
- min3d引擎使用指南(Android)<三>
- Android UI 优化 使用<include/>和 <merge />标签
- html<select>控件使用体会
- 【MySql】使用记录<三>
- 使用GDB调试GO<三>
- 使用设计模式优化设计案例<一>
- 黑马程序员—iOS- <项目笔记>UI控件常见属性总结(下)
- Android UI设计之<三>自定义EditText,实现带清除功能的输入框
- AndroidStudio 中使用 百度地图 <三> 百度地图的定位的集成和使用,个人摘要
- Android UI设计之<六>使用HTML标签,实现在TextView中对部分文字进行加粗显示
- Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结: 先看下面的代码: <shape>
- Flex使用<mx:Tree>控件创建树(可添加和删除节点)
- 黑马程序员—iOS- <项目笔记>UI控件常见属性总结(上)
- Lesson3 使用Hello ACCP.NET快速热身<三>