以下三个继承自UIScrollView:
UITableView 表格视图
UICollection 集合视图
UITextView 文本视图
滚动修改原理:修改自身bounds的值,
scrollView的直接子控件在添加约束时比平常情况要多加
1.要设置四边边距
2.要设置明确的宽和高
因为在添加约束时要计算子控件的frame还要计算scrollViewContentSize
//水平滚动图片
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
//设置背景
sv.backgroundColor = [UIColor grayColor];
//添加到视图
[self.view addSubview:sv];
//设置滚动区域(多大才能装的下四张图片)
sv.contentSize = CGSizeMake(375*12, 667);
//把图片装进去
for(int i = 0; i < 11; i++)
{
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"icon_zd",i]];
UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(375*i, 0, 375, 667)];
imgV.image = img;
[sv addSubview:imgV];
}
//分页显示
sv.pagingEnabled = YES;
//是否允许反弹
sv.bounces = NO;
//修改滚动条的样式(能滚动时有弹簧,不能滚动时就没有弹簧)
sv.indicatorStyle = UIScrollViewIndicatorStyleWhite ;
//隐藏滚动条
sv.showsHorizontalScrollIndicator = NO;//水平
sv.showsVerticalScrollIndicator = NO;//垂直
//滑动到指定位置(偏移量)
sv.contentOffset = CGPointMake(375, 0);
}
