#define NewfeatureCount 4
@interface NewfeatureViewController ()<UIScrollViewDelegate>
@property(nonatomic,weak) UIPageControl *pageControl;
@end
- (void)viewDidLoad {
[super viewDidLoad];
//创建一个scrollview:显示所有的新特性
UIScrollView *scrollView = [[UIScrollView alloc]init];
scrollView.frame = self.view.bounds;
[self.view addSubview:scrollView];
for (int i = 0; i < NewfeatureCount; i++) {
UIImageView *image = [[UIImageView alloc]init];
image.size = scrollView.size;
image.y = 0 ;
image.x = i * image.width;
//显示图片
NSString *name = [NSString stringWithFormat:@"new_feature_%d",i+1];
image.image = [UIImage imageNamed:name];
[scrollView addSubview:image];
}
//如果想要某个方向不能滚动,那就就该方向上的值设置为0
scrollView.contentSize = CGSizeMake(NewfeatureCount * scrollView.width, 0);
scrollView.bounces = NO;//去除弹簧效果
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.delegate = self;
//添加pageControl:设置分页
UIPageControl *pageControl = [[UIPageControl alloc]init];
pageControl.numberOfPages = NewfeatureCount;
pageControl.width = 100;
pageControl.height = 50;
//pageControl.backgroundColor = [UIColor redColor];
pageControl.centerX = scrollView.width * 0.5;
pageControl.centerY = scrollView.height -50;
pageControl.currentPageIndicatorTintColor = [UIColor redColor];
pageControl.pageIndicatorTintColor = [UIColor grayColor];
pageControl.userInteractionEnabled = NO;//不许与用户界面交互
[self.view addSubview:pageControl];
self.pageControl = pageControl;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
double page = scrollView.contentOffset.x / scrollView.width;
//四舍五入计算页面
self.pageControl.currentPage = (int)(page + 0.5);
}
@interface NewfeatureViewController ()<UIScrollViewDelegate>
@property(nonatomic,weak) UIPageControl *pageControl;
@end
- (void)viewDidLoad {
[super viewDidLoad];
//创建一个scrollview:显示所有的新特性
UIScrollView *scrollView = [[UIScrollView alloc]init];
scrollView.frame = self.view.bounds;
[self.view addSubview:scrollView];
for (int i = 0; i < NewfeatureCount; i++) {
UIImageView *image = [[UIImageView alloc]init];
image.size = scrollView.size;
image.y = 0 ;
image.x = i * image.width;
//显示图片
NSString *name = [NSString stringWithFormat:@"new_feature_%d",i+1];
image.image = [UIImage imageNamed:name];
[scrollView addSubview:image];
}
//如果想要某个方向不能滚动,那就就该方向上的值设置为0
scrollView.contentSize = CGSizeMake(NewfeatureCount * scrollView.width, 0);
scrollView.bounces = NO;//去除弹簧效果
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.delegate = self;
//添加pageControl:设置分页
UIPageControl *pageControl = [[UIPageControl alloc]init];
pageControl.numberOfPages = NewfeatureCount;
pageControl.width = 100;
pageControl.height = 50;
//pageControl.backgroundColor = [UIColor redColor];
pageControl.centerX = scrollView.width * 0.5;
pageControl.centerY = scrollView.height -50;
pageControl.currentPageIndicatorTintColor = [UIColor redColor];
pageControl.pageIndicatorTintColor = [UIColor grayColor];
pageControl.userInteractionEnabled = NO;//不许与用户界面交互
[self.view addSubview:pageControl];
self.pageControl = pageControl;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
double page = scrollView.contentOffset.x / scrollView.width;
//四舍五入计算页面
self.pageControl.currentPage = (int)(page + 0.5);
}