标签:
1、UIScrollView 滚动视图
// 滚动视图
UIScrollView* scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
// **设置滚动内容的大小
//如果size值为0,默认是scroll.bounds的宽高 若设置height为0 则不支持上下滑动
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width * 2, self.view.bounds.size.height * 2);
// ** 设置当前滚动的位置
scrollView.contentOffset = CGPointMake(200, 200);
// 将内容添加到滚动视图上
[scrollView addSubview:imageView];
// 锁定方向
scrollView.directionalLockEnabled = YES;
// 设置弹力效果
scrollView.bounces = NO;
// 当内容大小小于scroll.bouns 的大小默认不可以拖动
// alwaysBounceVertical, alwaysBounceHorizontal 设置为YES,则可以拖动
scrollView.alwaysBounceVertical = YES;
scrollView.alwaysBounceHorizontal = YES;
// 将内容分页展示
scrollView.pagingEnabled = YES;
// 开启是否滚动
scrollView.scrollEnabled = NO;
// 设置是否显示滚动条
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
// 设置滚动条的风格
scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
// 设置是否点击状态栏可以滑至顶端
scrollView.scrollsToTop = NO;
// 给滚动视图添加内边距
scrollView.contentInset = UIEdgeInsetsMake(100, 100, 100, 100);
// 给滚动条添加内边距
scrollView.scrollIndicatorInsets =UIEdgeInsetsMake(50, 0, 0, 0);
// 减速速率0.1~1
scrollView.decelerationRate = 99;
[self.view addSubview:scrollView];
// ** 设置做大缩放比例
scrollView.maximumZoomScale = kMaxZoomScale;
// ** 设置做小缩放比例
scrollView.minimumZoomScale = kMinZoomScale;
// ** 设置缩放的弹力
scrollView.bouncesZoom = YES;
// 缩放至某一区域
[self.scrollView zoomToRect:rect animated:YES];
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
2、UIScrollView常用代理 <UIScrollViewDelegate>
//正在滚动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {}
//开始拖拽 手指没有离开屏幕 Dragging拖拽 当用户开始拖拽的时候就调用
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {}
//拖拽结束 手指离开屏幕 当用户停止拖拽的时候调用
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {}
//开始减速 Decelerating减速
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {}
//减速停止
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {}
//返回需要缩放的视图
- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {}
//开始缩放
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view {}
//结束缩放
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale {}
//缩放动作开始至结束
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {}
3、UIPageControl 分页控件
//分页控件初始化
UIPageControl * pageControl = [[UIPageControl alloc] init];
//分页页数
pageControl.numberOfPages = 5;
//当前页数
pageControl.currentPage = 0;
//如果仅有一页,隐藏pageControl
pageControl.hidesForSinglePage = YES;
//根据页数获取UIPageControl的大小
CGSize pageControlSize = [pageControl sizeForNumberOfPages:5];
//设置未选中指示点的颜色
pageControl.pageIndicatorTintColor = [UIColor greenColor];
//设置当前指示点的颜色
pageControl.currentPageIndicatorTintColor = [UIColor redColor];
标签:
原文地址:http://www.cnblogs.com/PSSSCode/p/5272025.html