/**
* 添加pageControl
*/
- (void)setupPageControl
{
// 1.添加
UIPageControl *pageControl = [[UIPageControl alloc] init];
pageControl.numberOfPages = NewfeatureImageCount;
CGFloat centerX = self.view.frame.size.width * 0.5;
CGFloat centerY = self.view.frame.size.height - 30;
pageControl.center = CGPointMake(centerX, centerY);
pageControl.bounds = CGRectMake(0, 0, 100, 30);
pageControl.userInteractionEnabled = NO;
[self.view addSubview:pageControl];
self.pageControl = pageControl;
// 2.设置圆点的颜色
pageControl.currentPageIndicatorTintColor = RGB(253, 98, 42,1);
pageControl.pageIndicatorTintColor = RGB(189, 189, 189,1);
}
/**
* 添加UISrollView
*/
- (void)setupScrollView
{
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.frame = self.view.bounds;
scrollView.delegate = self;
[self.view addSubview:scrollView];
// 2.添加图片
CGFloat imageW = scrollView.frame.size.width;
CGFloat imageH = scrollView.frame.size.height;
NSArray *imageArr = @[@"引导页01-背景",@"引导页02",@"引导页03"];
for (int index = 0; index<NewfeatureImageCount; index++) {
UIImageView *imageView = [[UIImageView alloc] init];
// 设置图片
imageView.image = [UIImage imageNamed:imageArr[index]];
// 设置frame
CGFloat imageX = index * imageW;
imageView.frame = CGRectMake(imageX, 0, imageW, imageH);
[scrollView addSubview:imageView];
// 在最后一个图片上面添加按钮
if (index == NewfeatureImageCount - 1) {
[self setupLastImageView:imageView];
}
}
// 3.设置滚动的内容尺寸
scrollView.contentSize = CGSizeMake(imageW * NewfeatureImageCount, 0);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.pagingEnabled = YES;
scrollView.bounces = NO;
}
/**
* 只要UIScrollView滚动了,就会调用
*
*/
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// 1.取出水平方向上滚动的距离
CGFloat offsetX = scrollView.contentOffset.x;
// 2.求出页码
double pageDouble = offsetX / scrollView.frame.size.width;
int pageInt = (int)(pageDouble + 0.5);
self.pageControl.currentPage = pageInt;
}