首页 > 代码库 > UI 常用方法总结之--- UIScrollView (不断更新中)
UI 常用方法总结之--- UIScrollView (不断更新中)
UIScrollView :UIView <NSCoding>
1.创建一个UIScrollView对象
UIScrollView *scrollView = [[UIScrollViewalloc]initWithFrame:CGRectMake(20,20, 280, 280)];
2.backgroundColor
背景颜色
3.contentSize
设置滚动范围
eg:scrollView.contentSize =CGSizeMake(1000, 1000);
4.contentOffset
偏移量 (初始显示)(scrollView 相对于滚动范围的坐标)
eg:scrollView.contentOffset =CGPointMake(500 , 50);
5.contentInset
可滚动的范围距离上左下右的距离
eg:scrollView.contentInset =UIEdgeInsetsMake(100, 50, 0, 0);
6.bounces
到达边缘之后没有弹动效果
eg:scrollView.bounces =NO;
7.scrollsToTop
允许用户点击状态栏返回顶部
eg:scrollView.scrollsToTop =YES;
8.scrollEnabled
是否允许用户滚动
eg:scrollView.scrollEnabled =NO;
9.pagingEnabled
按页滚动
eg:scrollView.pagingEnabled =YES;
10.showsHorizontalScrollIndicator
隐藏横向滚动条 滚动条实际上是加在scrollView上的两个imageView
eg:scrollView.showsHorizontalScrollIndicator =NO;
11.showsVerticalScrollIndicator
隐藏纵向滚动条
eg:scrollView.showsVerticalScrollIndicator =NO;
UIScrollViewDelegate
12.maximumZoomScale
设置scrollView缩放的范围
eg:scrollView.maximumZoomScale =2.0;
13.minimumZoomScale
设置scrollView缩放的范围
eg:scrollView.minimumZoomScale =0.5;
14.- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
eg:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
//返回一个view 跟着scrillView缩放
//会把scrollView的contentSize设置为imageView的大小
//同时只能有一个view跟着scrollView缩放
return [scrollView.subviewsfirstObject];
}
15.- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
eg:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// NSLog(@"%@",NSStringFromCGPoint(scrollView.contentOffset));
// NSLog(@"偏移量改变了");
//在偏移量改变的时候,计算当前的页数
int pageNumber = scrollView.contentOffset.x / scrollView.frame.size.width;
//通过偏移量改变pageControl的值
self.pageControl.currentPage = pageNumber;
}
16.- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"将要开始拖拽");
}
17.- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"已经结束拖拽");
}
18.- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
NSLog(@"将要开始减速");
}
19.- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"已经减速停止");
}
UI 常用方法总结之--- UIScrollView (不断更新中)