Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective-C iOS如何将UIPageControl添加到我的CollectionView?_Ios_Objective C_Xcode - Fatal编程技术网

Objective-C iOS如何将UIPageControl添加到我的CollectionView?

Objective-C iOS如何将UIPageControl添加到我的CollectionView?,ios,objective-c,xcode,Ios,Objective C,Xcode,我有一个可翻页和水平滚动的collectionView。 我只想在滚动时将pageControl的点添加到我的collectionView中。尝试如下: -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ // Suppose your collectionview cell width is equal to your screen size CGFloat collectionViewCellWidth = se

我有一个可翻页和水平滚动的collectionView。 我只想在滚动时将pageControl的点添加到我的collectionView中。

尝试如下:

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
 // Suppose your collectionview cell width is equal to your screen size
 CGFloat collectionViewCellWidth = self.view.frame.size.width;     
_pageControl.currentPage = (scrollView.contentOffset.x / collectionViewCellWidth);
}

实现滚动视图的委托方法,如下所示:-

说出CollectionViewTestional:NameIBOutlet您的集合视图,PageControlTestional:page控件的名称

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGFloat pageWidth = collectionViewTestimonial.frame.size.width;
    pageControlTestimonial.currentPage = collectionViewTestimonial.contentOffset.x / pageWidth;
}

设置页面控件中的页数

NSUInteger numberOfCells = 10;
_pageControl.numberOfPages = numberOfCells;
实现scrollView委托方法

 -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
 // Suppose your collectionview cell width is equal to your screen size
 CGFloat collectionViewCellWidth = self.view.frame.size.width;     
_pageControl.currentPage = (scrollView.contentOffset.x / collectionViewCellWidth);
}

在CollectionView上添加一个PageControl,实现UIScrollViewDelegate的ScrollViewDidScroll并设置PageControl的当前页面。我认为您回答了错误的问题。它工作正常。谢谢