1、新建storyboard项目 把UIScrollView 拖入view中
2、添加UIScrollView属性
@property (weak, nonatomic) IBOutlet UIScrollView * scrollView;
写入代码:
-(void)addImageView
{
CGFloat w =_scrollView.frame.size.width;
CGFloat h =_scrollView.frame.size.height;
for (int i=0; i<kCount; i++)
{
UIImageView * imageView=[UIImageView new];
imageView.frame=CGRectMake(i*w, 0, w, h);
NSString * imgName=[NSString stringWithFormat:@"welcome00%d.png",i+1];
imageView.image =[UIImage imageNamed:imgName];
[_scrollView addSubview:imageView];
}
_scrollView.contentSize=CGSizeMake(kCount*w, 0);
//不现实滚动条
_scrollView.showsHorizontalScrollIndicator=NO;
//分页设置
_scrollView.pagingEnabled = YES;
//设置代理
_scrollView.delegate = self;
[self createPageControlWidth:w height:h];
}
3、添加分页圆点:添加圆点属性
UIPageControl * _pageControl;
写入代码:
-(void)createPageControlWidth:(CGFloat)w height:(CGFloat)h
{
//创建圆点
UIPageControl * pageControl =[UIPageControl new];
//设置圆点宽高
pageControl.center = CGPointMake(w * 0.5, h-50);
pageControl.bounds=CGRectMake(0, 0, 150, 50);
//显示圆点个数
pageControl.numberOfPages=kCount;
[self.view addSubview:pageControl];
_pageControl=pageControl;
//禁止圆点按钮点击
pageControl.enabled = NO;
}
#pragma mark scrollView代理方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
int page=scrollView.contentOffset.x / scrollView.frame.size.width;
//设置页码
_pageControl.currentPage=page;
if (page==4)
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}