更改页面控件的位置

时间:2019-02-06 06:32:28

标签: ios swift uipagecontrol

我有一个页面控制器,该控制器具有4个页面,在前三个页面中,页面指示器位于屏幕底部,在最后一个页面中,我想将其更改为顶部

 func newVc(viewController: String) -> UIViewController {
    return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: viewController)
}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
    guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
        return nil
    }
    let previousIndex = viewControllerIndex - 1
    guard previousIndex >= 0 else {
        return orderedViewControllers.last
    }
    guard orderedViewControllers.count > previousIndex else {
        return nil
    }
    return orderedViewControllers[previousIndex]
}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
    guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
        return nil
    }
    let nextIndex = viewControllerIndex + 1
    let orderedViewControllersCount = orderedViewControllers.count
    guard orderedViewControllersCount != nextIndex else {
        return orderedViewControllers.first
    }
    guard orderedViewControllersCount > nextIndex else {
        return nil
    }
    return orderedViewControllers[nextIndex]
}

func configurePageControl() {
  many available colors we have.
    pageControl = UIPageControl(frame: CGRect(x: 0,y: UIScreen.main.bounds.maxY - 50,width: UIScreen.main.bounds.width,height: 50))
    self.pageControl.numberOfPages = orderedViewControllers.count
    self.pageControl.currentPage = 0
    self.pageControl.tintColor = UIColor.black
    self.pageControl.pageIndicatorTintColor = UIColor.white
    self.pageControl.currentPageIndicatorTintColor = UIColor.black
    self.view.addSubview(pageControl)
}

1 个答案:

答案 0 :(得分:0)

当您到达页面视图控制器中的特定索引时,在页面控制框中更改y position

尝试以下代码:

pageControl.frame = CGRect(x: 0, y: 70, width: UIScreen.main.bounds.width, height: 50)

根据需要调整Y在框架中的位置。