zoukankan      html  css  js  c++  java
  • UIscrollview












    #import
    "DengViewController.h" @interface DengViewController () @end @implementation DengViewController @synthesize pc=_pc; - (void)viewDidLoad { [super viewDidLoad]; CGRect rect= CGRectMake(20, 20, width, height); UIScrollView *scrollew = [[UIScrollView alloc] initWithFrame:rect]; scrollew.backgroundColor=[UIColor blueColor]; scrollew.delegate=self; NSString *imageName; UIImage *im; UIImageView *iv; for (int i=0; i<pictures; i++) { imageName=[NSString stringWithFormat:@"%d.png",i+1]; im=[UIImage imageNamed:imageName]; rect=CGRectMake(width*i, 0, width, height); iv=[[UIImageView alloc] initWithFrame:rect]; iv.image=im; [scrollew addSubview:iv]; } ///设置滑动范围 scrollew.contentSize=CGSizeMake(width*pictures, height); ///设置滑动时显示条的风格 scrollew.indicatorStyle=UIScrollViewIndicatorStyleWhite; //关闭弹跳 .yes可以拉 scrollew.bounces=YES; //水平方向滑动指示器 // scrollew.showsHorizontalScrollIndicator=NO; ///一页一页滑动,no可以暂停 scrollew.pagingEnabled=YES; [self.view addSubview:scrollew]; rect=CGRectMake(20, 370, width, 20); UIPageControl *pc = [[UIPageControl alloc] initWithFrame:rect]; //点的 pc.userInteractionEnabled=NO; ///指定指示的个数 pc.numberOfPages=pictures; pc.backgroundColor=[UIColor blackColor]; self.pc=pc; [self.view addSubview:pc]; // Do any additional setup after loading the view, typically from a nib. } - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ ///当用户滑动scrollview时.触发 self.pc.currentPage=(width/2+scrollView.contentOffset.x)/width; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
  • 相关阅读:
    未处理的异常 stack overflow
    Largest Rectangle in a Histogram [POJ2559] [单调栈]
    Blocks [POJ3734] [矩阵快速幂]
    Rectangular Covering [POJ2836] [状压DP]
    Arrange the Bulls [POJ2441] [状压DP]
    The Water Bowls [POJ3185] [开关问题]
    Bound Found [POJ2566] [尺取法]
    4 Values whose Sum is 0 [POJ2785] [折半搜索]
    Physics Experiment 弹性碰撞 [POJ3684]
    Fliptile [POJ3279] [开关问题]
  • 原文地址:https://www.cnblogs.com/deng37s/p/4574030.html
Copyright © 2011-2022 走看看