#import "ViewController.h"
#define KScreenW [UIScreen mainScreen].bounds.size.width
#define KScreenH [UIScreen mainScreen].bounds.size.height
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
/*——————————————————————————UIScrollView 滑动视图————————————————————————————————————————————————————-*/
//1.创建
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, KScreenW, KScreenW)];
scrollView.backgroundColor = [UIColor grayColor];
[self.view addSubview:scrollView];
//2.
//1.尺寸
scrollView.contentSize = CGSizeMake(5 * KScreenW, KScreenW);
//2.是否开启分页 默认NO
scrollView.pagingEnabled = YES;
//3.是否开启滚动条 默认YES
//水平
scrollView.showsHorizontalScrollIndicator = YES;
//垂直
scrollView.showsVerticalScrollIndicator = NO;
//4.滑动条样式
/**
*
UIScrollViewIndicatorStyleDefault, // black with white border. good against any background 系统默认滑动条
UIScrollViewIndicatorStyleBlack, // black only. smaller. good against a white background 黑色的滑动条
UIScrollViewIndicatorStyleWhite // white only. smaller. good against a black background 白色的滑动条
*/
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
//5.是否开启首位反弹效果 默认YES
//滑动
scrollView.bounces = YES;
//缩放
scrollView.bouncesZoom = YES;
//6.是否开启滚动 默认YES
scrollView.scrollEnabled = YES;
//7.item的偏移量
// scrollView.contentInset = UIEdgeInsetsMake(0, 50, 0, 50);
//8.content 的偏移量
// scrollView.contentOffset = CGPointMake(2*KScreenW, 0);
//两秒后才偏移
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[scrollView setContentOffset:CGPointMake(2 *KScreenW, 0) animated:YES];
});
//获取图片
for (int i = 0; i < 5; i++) {
//获取照片
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"scene%d.jpg",i+1]];
//imageView的大小
UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i* KScreenW, 0, KScreenW, KScreenW)];
//把图片放入图片视图
imageV.image = image;
//把图片视图放入scrollView里
[scrollView addSubview:imageV];
}
}
@end
Day.03.04 UIScrollView 滑动视图
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- ![Uploading 屏幕快照 2016-03-04 下午7.21.33_759992.png . . .]
- 大纲 一、代理项目:CustomAlertView03171.基本概念案例:点击alertView(委托者)上的按...
- 好久没写博客了,这段时间事情比较多,心情也不是很美妙,但是代码还是要继续啊!今天分享的是自定义的一个ScrollV...