问题描述
有没有办法可以在我的应用中独立使用这些分页点,
Is there a way that I can use those paging dots independently in my app,
将它们添加到我的UIView/NIB并调用其上的函数以设置点总数或当前页面/点.
add them to my UIView/NIB and call the functions on it to set total number of dots or current page/dot.
基本上,我将UIViewImage保存在nib文件中,我正在以滑动手势显示图像(取自数组的名称),并希望在底部显示这些分页点以获取导航信息.
Basically I've UIViewImage in a nib file, i'm displaying images (names taken off an array) on swipe gestures and want to show those paging dots on the bottom for the navigation information.
推荐答案
UIPageControl
的总页面数&正如您所描述的那样,假设 pageControl
是 UIPageControl
的实例,那么您可以启动 numberOfPages
& currentPage
如下:
UIPageControl
has it's total page & current page/dot just as you described, let's say pageControl
is a instance of UIPageControl
, then you can initiate the numberOfPages
& currentPage
as below:
pageControl.numberOfPages = [images count];
pageControl.currentPage = 0;
此外,您可以在点击 pageControl
的点时为其添加操作. changePage:
方法仅是示例:
Also, you can add action for it when the pageControl
's dots was tapped. changePage:
method here is just a example:
[pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
您可以将图像添加到 UIScrollView
并使用其委托方法: scrollViewDidScroll:
:
You can add your images to a UIScrollView
and use its delegate method: scrollViewDidScroll:
:
- (void)scrollViewDidScroll:(UIScrollView *)sender {
// Update the page number
CGFloat pageWidth = scrollView.frame.size.width;
pageControl.currentPage = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
}
当您滑动到新图像时,它将更改 pageControl
的当前点.
It'll change the pageControl
's current dot when your swiped to a new image.
这篇关于iOS分页控件(导航)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!