UIScrollView
//UIScrollView滚动视图
UIScrollView *scroll= [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,[[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height)];
scroll.backgroundColor= [UIColor redColor];
//设置scrollde容量
scroll.contentSize=CGSizeMake(14*[[UIScreenmainScreen]bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
//隐藏滑动指示器(水平方向Horizontal)
scroll.showsHorizontalScrollIndicator=YES;
//垂直方向滑动指示器设置隐藏
scroll.showsVerticalScrollIndicator=NO;
[self.view addSubview:scroll];
for(inti = 0; i < 14; i ++) {
UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width*i, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen]bounds].size.height)];
imageview.image= [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]];
//翻页属性,设置为YES不会出现半页的情况
scroll.pagingEnabled=YES;
//弹性属性设置为NO :首尾不可以再滑动
scroll.bounces=NO;
[scroll addSubview:imageview];
}
//UIPageControl一类对象
page= [[UIPageControl alloc] initWithFrame:CGRectMake(([[UIScreenmainScreen]bounds].size.width-80)/2.0,[[UIScreen mainScreen]bounds].size.height-30, 80, 20)];
page.currentPageIndicatorTintColor= [UIColor blackColor];
page.numberOfPages=14;
//层上加层按提交顺序就不会被上一层覆盖
[self.view addSubview:page];
///定时器
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(autoScroll) userInfo:nil repeats:YES];
}
- (void)autoScroll {
staticint a=0;
staticint x=0;
staticint i=1;
x += i*[[UIScreen mainScreen] bounds].size.width;
//a=a+i
a += i;
if(a == 13) {
i = -1;
}
if(a == 0) {
i = 1;
}
//setContentOffset:设置偏移量 animated;是否平缓过度
[scroll setContentOffset:CGPointMake(x, 0) animated:YES];
page.currentPage= a;
}