UIScrollView 基本用法
2016-01-09 01:13
465 查看
UIScrollView *sc=[UIScrollView alloc]initWithFrame:CGRectMake(0,0,300,500)];
设置包含的尺寸。
sc.contentSize = CGSizeMake(1200, 499);
设置偏移值
sc.contentOffset= CGPointMake(300, 0)
控制四周额外增加的contentInset
sc.contentInset = UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
弹簧效果bounces 默认是YES;
sc.bounces
=YES/NO;
设置是否允许滚动scrollEnabled
设置是否显示拖动条
sc.showsHorizontalScrollIndicator横向
sc.showsVerticalScrollIndicator纵向
当内容大小小于空间尺寸的时候,还有弹簧效果。默认no;
sc.alwaysBounceHorizontal
sc.alwaysBounceVertical
分页显示开关,默认no;
sc.pagingEnabled
设定滚动条的样式
UIScrollViewIndicatorStyle indicatorStyle
sc.indicatorStyle = UIScrollViewIndicatorStyleWhite; 白
sc.indicatorStyle = UIScrollViewIndicatorStyleBlack; 黑
sc.indicatorStyle = UIScrollViewIndicatorStyleDefault; 灰 默认
UIscrollView 的协议
<UIScrollViewDelegate>时间点的应用(常用)。
手势缩放
设置UIScrollView的id<UISCrollViewDelegate>
delegate代理对象
设置minimumZoomScale :缩小的最小比例
设置maximumZoomScale :放大的最大比例
让代理对象实现下面的方法,返回需要缩放的视图控件
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
跟缩放相关的常用方法还有;
正在缩放的时候调用
-(void)scrollViewDidZoom:(UIScrollView *)scrollView
缩放完毕的时候调用
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
分页效果
设置pagingEnabled=YES即可,UIScrollView会被分割成多个独立页面,用户的滚动体验则变成了页面翻转
一般会配合UIPageControl增强分页效果,UIPageControl常用属性:
NSInteger numberOfPages : 总页数
NSInteger currentPage : 当前的页码
BOOL hidesForSinglePage : 当只有一页的时候,是否要隐藏视图
监听UIPageControl的页面改变:
// 添加监听器
[pageControl addTarget:self action:@selector(pageChange:)
forControlEvents:UIControlEventValueChanged];
// 监听方法
- (void)pageChange:(UIPageControl *)pageControl
{
}
设置包含的尺寸。
sc.contentSize = CGSizeMake(1200, 499);
设置偏移值
sc.contentOffset= CGPointMake(300, 0)
控制四周额外增加的contentInset
sc.contentInset = UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
弹簧效果bounces 默认是YES;
sc.bounces
=YES/NO;
设置是否允许滚动scrollEnabled
设置是否显示拖动条
sc.showsHorizontalScrollIndicator横向
sc.showsVerticalScrollIndicator纵向
当内容大小小于空间尺寸的时候,还有弹簧效果。默认no;
sc.alwaysBounceHorizontal
sc.alwaysBounceVertical
分页显示开关,默认no;
sc.pagingEnabled
设定滚动条的样式
UIScrollViewIndicatorStyle indicatorStyle
sc.indicatorStyle = UIScrollViewIndicatorStyleWhite; 白
sc.indicatorStyle = UIScrollViewIndicatorStyleBlack; 黑
sc.indicatorStyle = UIScrollViewIndicatorStyleDefault; 灰 默认
UIscrollView 的协议
<UIScrollViewDelegate>时间点的应用(常用)。
手势缩放
设置UIScrollView的id<UISCrollViewDelegate>
delegate代理对象
设置minimumZoomScale :缩小的最小比例
设置maximumZoomScale :放大的最大比例
让代理对象实现下面的方法,返回需要缩放的视图控件
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
跟缩放相关的常用方法还有;
正在缩放的时候调用
-(void)scrollViewDidZoom:(UIScrollView *)scrollView
缩放完毕的时候调用
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
分页效果
设置pagingEnabled=YES即可,UIScrollView会被分割成多个独立页面,用户的滚动体验则变成了页面翻转
一般会配合UIPageControl增强分页效果,UIPageControl常用属性:
NSInteger numberOfPages : 总页数
NSInteger currentPage : 当前的页码
BOOL hidesForSinglePage : 当只有一页的时候,是否要隐藏视图
监听UIPageControl的页面改变:
// 添加监听器
[pageControl addTarget:self action:@selector(pageChange:)
forControlEvents:UIControlEventValueChanged];
// 监听方法
- (void)pageChange:(UIPageControl *)pageControl
{
}
相关文章推荐
- fatal error UISCrollview.h: No such file or directory
- [iOS] UICollectionView实现图片水平滚动
- UI 控件介绍
- UIDatepicker日期选择框的使用与日期键盘的定义
- UITableView 的简单介绍
- Quartz2D---苹果官方的⼆维绘图引擎(绘制基本图形)
- 14、UI_02拨号盘动画
- yuicompressor-maven-plugin插件-用于压缩js,css
- iOS:笔记:UIButton
- 【ZBar】ios错误ignoring file xxx missing required architecture x86_64 in file
- IOS UIView圆角,阴影,边框,渐增光泽
- 解决UITableView分割线距左边有距离的办法
- 优先级队列(大顶堆)
- 关于UIView类的frame属性和bounds属性的origin点的区别
- iOS UITableView(十一) tableView的下拉刷新
- requirejs——基础
- EasyUi之menubutton
- IOS开发 UI UISlider
- java中continue,return,break的区别
- SQL Server IP地址格式转换(GUID To String)