UIScrollView基础
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 //滚动视图,可以对屏幕内容进行滚屏查看。 4 5 UIScrollView* sv = [[UIScrollView alloc]init]; 6 7 sv.frame = CGRectMake(0, 0, 320, 576); 8 //设置背景颜色 9 sv.backgroundColor = [UIColor orangeColor]; 10 11 //设置画布的大小,画布显示在滚动视图内部,一般大于frame的大小。 12 sv.contentSize = CGSizeMake(320,576*5); 13 // 是否按照整页来滚动 14 sv.pagingEnabled = YES; 15 // 是否可以开启滚动效果 16 sv.scrollEnabled = YES; 17 18 //是否可以边缘弹动效果 19 sv.bounces = YES; 20 //开启横向弹动效果 21 sv.alwaysBounceHorizontal = YES; 22 //开启纵向弹动效果 23 sv.alwaysBounceVertical = YES; 24 //显示横向滚动条 25 sv.showsHorizontalScrollIndicator = YES; 26 //显示纵向滚动条 27 sv.showsVerticalScrollIndicator = YES; 28 29 for(int i=0;i<2;i++) 30 { 31 NSString* strName = [NSString stringWithFormat:@"%d.jpg",i+1]; 32 UIImage* image = [UIImage imageNamed:strName]; 33 34 UIImageView* iView = [[UIImageView alloc] initWithImage:image]; 35 36 iView.frame = CGRectMake(0, 576*i, 320, 576); 37 38 [sv addSubview:iView]; 39 40 } 41 42 [self.view addSubview:sv]; 43 44 }