//创建ScrollView
UIScrollView *sv = [[UIScrollView alloc] init];
sv.frame = self.view.bounds;
//设置边缘不弹跳
sv.bounces = NO;
//整页滚动
sv.pagingEnabled = YES;
sv.showsHorizontalScrollIndicator = NO;
NSArray *array = @[@"1",@"2",@"3",@"4"];
for(NSInteger i=0; i < array.count ; i++){
NSString *imgName = [NSString stringWithFormat:@"%ld", i+1];
UIImage *image = [UIImage imageNamed:imgName];
UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
CGRect frame = CGRectZero;
frame.origin.x = i * sv.frame.size.width;
frame.size = sv.frame.size;
imageView.frame = frame;
[sv addSubview:imageView];
if(i== array.count - 1){
//开启图片的用户点击功能
imageView.userInteractionEnabled = YES;
//加个按钮
UIButton *button = [[UIButton alloc]init];
button.frame = CGRectMake((imageView.frame.size.width-150)/2, imageView.frame.size.height*0.8, 150, 40);
button.backgroundColor = [UIColor orangeColor];
[button setTitle:@"立即体验" forState:UIControlStateNormal];
button.titleLabel.font = [UIFont boldSystemFontOfSize:16];
[imageView addSubview:button];
[button addTarget:self action:@selector(enter) forControlEvents:UIControlEventTouchUpInside]; }
}
sv.contentSize = CGSizeMake(array.count * sv.frame.size.width, sv.frame.size.height);
//右上角的跳转按钮
UIButton *SkipButton = [[UIButton alloc]init];
SkipButton.frame = CGRectMake(self.view.frame.size.width - 100, 40 , 80 , 30);
SkipButton.backgroundColor = [UIColor redColor];
[SkipButton setTitle:@"跳过" forState:UIControlStateNormal];
SkipButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
[SkipButton addTarget:self action:@selector(SkipButton) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:sv];
[self.view addSubview:SkipButton];
//加入页面指示控件PageControl
UIPageControl *pageControl = [[UIPageControl alloc]init];
self.pageControl = pageControl;
//设置frame
pageControl.frame = CGRectMake(0, self.view.frame.size.height - 40, self.view.frame.size.width, 20);
//分页面的数量
pageControl.numberOfPages = array.count;
//设置小圆点渲染颜色
pageControl.pageIndicatorTintColor = [UIColor whiteColor];
//设置当前选中小圆点的渲染颜色
pageControl.currentPageIndicatorTintColor = [UIColor redColor];
//关闭用户点击交互
pageControl.userInteractionEnabled = NO;
[self.view addSubview:pageControl];
sv.delegate = self;