UIScrollView基础用法、属性
2017-10-12 本文已影响0人
李琪_59dc
- alloc init 创建滚动视图
- .frame 设置滚动视图的位置
- .pagingEnabled 是否支持按整页来滚动视图
- .scrollEnabled 是否开启滚动效果
- .contentSize 设置画布大小,画布显示在滚动视图内部,一般大于frame的大小
- .bounces 是否开启边缘弹动效果
- .alwaysBounceHorizontal 水平方向弹动效果
- .alwaysBounceVertical 垂直方向弹动效果
- .showHorizontalScrollIndicator 显示横向滚动条
- .showVerticalScrollIndicator 显示纵向滚动条
- .backgroundColor
具体使用:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIScrollView* scrollView = [[UIScrollView alloc]init];
scrollView.frame = CGRectMake(0, 0, 320, 576);
//是否按照整页来滚动视图
scrollView.pagingEnabled = YES;
//是否可以开启滚动效果
scrollView.scrollEnabled = YES;
//设置画布大小,画布显示在滚动视图内部,一般大小大于frame的大小
scrollView.contentSize = CGSizeMake(320*5, 576);
//是否开启边缘弹动效果
scrollView.bounces = YES;
scrollView.alwaysBounceHorizontal = YES;
scrollView.alwaysBounceVertical = YES;
//显示横向滚动条
scrollView.showsHorizontalScrollIndicator = YES;
//显示纵向滚动条
scrollView.showsVerticalScrollIndicator = YES;
scrollView.backgroundColor = [UIColor orangeColor];
//使用循环创建5张滚动视图
for(int i=0;i<5;i++){
NSString *strName = [NSString stringWithFormat:@"icon%d",i+1];
UIImage *image = [UIImage imageNamed:strName];
//创建图像视图
UIImageView *iView = [[UIImageView alloc]initWithImage:image];
//设置图像视图的位置
iView.frame = CGRectMake(320*i, 0, 320, 576);
[scrollView addSubview:iView];
}
[self.view addSubview:scrollView];
}