您的位置:首页 > 产品设计 > UI/UE

UIPageControl

2015-09-15 20:08 483 查看
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, 275, 30)];
_pageControl.center = CGPointMake(375 / 2, 667 - 100);

self.view.backgroundColor = [UIColor whiteColor];
//设置当前点的颜色
_pageControl.currentPageIndicatorTintColor = [UIColor purpleColor];
//设置其他点颜色
_pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
//设置点的个数
_pageControl.numberOfPages = 6;
//设置当前点的位置
_pageControl.currentPage = 0;
//添加事件
[_pageControl addTarget:self action:@selector(pageControlAction:) forControlEvents:UIControlEventValueChanged];

#pragma mark - 点击事件
-(void)pageControlAction:(UIPageControl *)pageControl
{
NSLog(@"%ld",pageControl.currentPage);
//设置scrollView的偏移量
_scrollView.contentOffset = CGPointMake(375 * pageControl.currentPage, 0);

}

-(void)tapAction:(UITapGestureRecognizer *)tap
{
UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"欢迎使用" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确认", nil];
[alerView show];

[alerView release];

[self.scrollView removeFromSuperview];
[self.pageControl removeFromSuperview];
}

//将要减速
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
_pageControl.currentPage = scrollView.contentOffset.x / 375;
}

//停止
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
_pageControl.currentPage = scrollView.contentOffset.x / 375;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: