您的位置:首页 > 产品设计 > UI/UE

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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: