UI控件使用案例<三>

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);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值