Pom*_*lus 11 uipagecontrol ios uipageviewcontroller swift
我正在实现一个简单的图库视图控制器,其中应用程序显示用户可以滚动的一小部分全屏图像.我正在使用UIPageViewController,我认为,如果我实现了正确的数据源函数,它应该自动显示页面控制指示器.但是我仍然看不到任何指标.
在我的主要GalleryViewController:
class GalleryViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
var pageController: UIPageViewController?
var pageContent = NSArray()
override func viewDidLoad() {
super.viewDidLoad()
.... some code to load images into the pageContent array ....
pageController = UIPageViewController(transitionStyle:.Scroll, navigationOrientation:.Horizontal,options:nil)
pageController?.delegate = self
pageController?.dataSource = self
... some more standard code to add the page controller to self.view etc.
var pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = UIColor.lightGray()
pageControl.currentPageIndicatorTintColor = UIColor.whiteColor()
pageControl.backgroundColor = UIColor.blackColor()
pageController!.didMoveToParentViewController(self)
}
func viewControllerAtIndex(index:Int) -> ContentViewController? {
....
}
Run Code Online (Sandbox Code Playgroud)
我已经实现了两个必需的协议方法viewControllerBeforeViewController和viewControllerAfterController以及两个必需的分页方法,presentationCountForPagesViewController和presentationIndexForPageViewController.
我ContentViewController有一个UIImageView填满整个屏幕.然而,即使我从屏幕底部减小尺寸,我也看不到任何页面指示灯.我错过了什么吗?如果我没有提供足够的信息,请告诉我.我一直在尝试重写我在5年前使用Objective-C编写的旧应用程序 - 完全在Swift中用于iOS8和Xcode等已经发生了很大变化,令人困惑.谢谢!
Zel*_* B. 24
取自这里:
为了显示UIPageControl,您需要实现两个可选的数据源方法.只返回presentationCountForPageViewController的整数页面以及最初为presentationIndexForPageViewController选择的索引
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return pageContent.count
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}
Run Code Online (Sandbox Code Playgroud)
Raf*_*sun 21
为什么不使用swell 3+版本的Zell B.的答案
func presentationCount(for pageViewController: UIPageViewController) -> Int {
return self.providerItemList?.providerItems?.count ?? 0
}
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return 0
}
Run Code Online (Sandbox Code Playgroud)
mil*_*czi 10
即使您将更改UIPageControl的颜色,它也可能不会出现.如果UIPageController在UITabBarController中,TabBar将覆盖UIPageControl.找到它的最佳方法是使用选项Debug-> View Debubging-> CaptureViewHierarchy.然后在左下角的过滤字段中输入"pageControl".如果你在导航器中点击它,它应该在屏幕上找到它(看一下截图)
您可以像这样更改位置:
let controlHeight: CGFloat = 50
let bottomSpace: CGFloat = 20
let yPosition = view.frame.size.height - (controlHeight + bottomSpace)
let fullScreenWidth = view.frame.size.width
let frame = CGRect(x: 0, y: yPosition, width: fullScreenWidth, height: controlHeight)
pageControl.frame = frame
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14779 次 |
| 最近记录: |