UI:UIScrollView滚动视图
发表时间:2020-10-19
发布人:葵宇科技
浏览次数:30
[img]http://img.blog.csdn.net/20150104160357546?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXR1emhhbmd6aXlhbw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
1.初始化
UIScrollView *scrollView = [[UIScrollViewalloc] init];
2.设置尺寸
(1)按照屏幕尺寸
scrollView.frame =self.view.bounds;
(2)自定义尺寸
scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
3.设置配风景
scrollView.backgroundColor = [UIColorredColor];
4.添加到View上
[self.viewaddSubview:scrollView];
5.在UIScrollView上添加image
//1.先初始化,再设置图片和尺寸
UIImageView *imageView = [[UIImageView alloc] init];
UIImage *image = [UIImage imageNamed:@"a11.jpg"];
imageView.image = image;
imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
[scrollView addSubview:imageView];
//2.先获得图片,经由过程图片去创建UIImageView
UIImage *image = [UIImageimageNamed:@"a9.jpg"];
_imageView = [[UIImageViewalloc] initWithImage:image];
[scrollViewaddSubview:_imageView];
其他属性设置:
//设置滚动区域 如不雅宽设为0 ,就不克不及程度滚动
scrollView.contentSize =CGSizeMake(image.size.width, image.size.height);
//设置当前滚动的地位(左上角的坐标)
scrollView.contentOffset =CGPointMake(500,500);
//在四周添加滚动范围
scrollView.contentInset =UIEdgeInsetsMake(0,0, 0, 0);
//设置是否显示显示滚动条(程度,垂直)
// scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator =NO;
//设置滚动条样式(三种)
scrollView.indicatorStyle =UIScrollViewIndicatorStyleBlack;
// scrollView.indicatorStyle = UIScrollViewIndicatorStyleDefault;
// scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
//设置是否可以滚动
scrollView.scrollEnabled =YES;
//设置弹性效不雅
// scrollView.bounces = NO;
//即使图片小于滚动范围,也可以用弹性效不雅
scrollView.alwaysBounceVertical =YES;
scrollView.alwaysBounceHorizontal =YES;
@interface ViewController () <UIScrollViewDelegate>
{
UIImageView *_imageView;
}
@end
//设置代劳为self
scrollView.delegate =self;
scrollView.maximumZoomScale =2;
#pragma mark 先肯定要缩放的控件是谁
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return _imageView;
}
scrollView.minimumZoomScale =0.5;