有没有办法可以在我的应用程序中独立使用这些分页点,

将它们添加到我的 UIView/NIB 并调用其上的函数来设置点总数或当前页面/点。

基本上,我在 nib 文件中有 UIViewImage,我在滑动手势上显示图像(从数组中提取的名称),并希望在底部显示那些分页点以获取导航信息。

最佳答案

UIPageControl 有它的总页面和当前页面/点,正如你所描述的,假设 pageControlUIPageControl 的一个实例,那么你可以启动 numberOfPagescurrentPage 如下:

pageControl.numberOfPages = [images count];
pageControl.currentPage = 0;

此外,您可以在点击 pageControl 的点时为其添加操作。这里的 changePage: 方法只是一个例子:
[pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];

您可以将图像添加到 UIScrollView 并使用其委托(delegate)方法: 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 的当前点。

关于iphone - iOS 分页控件(导航),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8475216/

10-13 01:50