首先需要创建一个引导页控制器,showViewController,然后在viewdidload中增加如下代码
UIScrollView* bgScrollView = [[UIScrollViewalloc]initWithFrame:self.view.bounds];
for(inti =0; i<_imageArray.count; i++) {
UIImage*image = [UIImageimageNamed:_imageArray[i]];
UIImageView*imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(self.view.frame.size.width* i,0,self.view.frame.size.width,self.view.frame.size.height)];
if(i==_imageArray.count-1) {
imageView.userInteractionEnabled=YES;
UIButton*button = [UIButtonbuttonWithType:UIButtonTypeSystem];
button.frame=CGRectMake(self.view.frame.size.width/3,self.view.frame.size.height*7/8,self.view.frame.size.width/3,self.view.frame.size.height/16);
[buttonsetTitle:@"点击进入"forState:UIControlStateNormal];
[buttonsetTitleColor:[UIColorwhiteColor]forState:UIControlStateNormal];
button.layer.borderWidth=2;
button.layer.cornerRadius=5;
button.clipsToBounds=YES;
button.layer.borderColor= [UIColorwhiteColor].CGColor;
[buttonaddTarget:selfaction:@selector(go:)forControlEvents:UIControlEventTouchUpInside];
[imageViewaddSubview:button];
}
imageView.image= image;
[bgScrollViewaddSubview:imageView];
}
bgScrollView.bounces=NO;
bgScrollView.pagingEnabled=YES;
bgScrollView.showsHorizontalScrollIndicator=NO;
bgScrollView.contentSize=CGSizeMake(self.view.frame.size.width*3,self.view.frame.size.height);
bgScrollView.delegate=self;
[self.viewaddSubview:bgScrollView];
_pageControl= [[UIPageControlalloc]initWithFrame:CGRectMake(self.view.frame.size.width/3,self.view.frame.size.height*15/16,self.view.frame.size.width/3,self.view.frame.size.height/16)];
//设置页数
_pageControl.numberOfPages=3;
//设置页码的点的颜色
_pageControl.pageIndicatorTintColor= [UIColoryellowColor];
//设置当前页码的点颜色
_pageControl.currentPageIndicatorTintColor= [UIColorredColor];
[self.viewaddSubview:_pageControl];
以上代码创建了一个ScrollView 一个pageControl scrollView主要用于承载启动页的图片,以及最后一页上的按钮,当然,按钮可以放在任何一页。
下一步是实现uiscrollview的代理方法,让uiscrollview的页数和pageControl的小圆点匹配
-(void)scrollViewDidScroll:(UIScrollView*)scrollView{
//计算当前在第几页
_pageControl.currentPage= (NSInteger)(scrollView.contentOffset.x/ [UIScreenmainScreen].bounds.size.width);
}
最后是点击按钮触发的事件:
ViewController* VC = [[ViewControlleralloc]init];
self.view.window.rootViewController= VC;
让主窗口返回到主页控制器上。
跟引导页相关的一个是启动页,启动页一般是固态图片和广告,目前只写固态图片的
固态图片最主要的就是延长时间的操作,可以在appdelegate中设置延时操作
[NSThreadsleepForTimeInterval:2];