【问题标题】:Change the Location of Page Control更改页面控件的位置
【发布时间】:2019-02-06 06:32:28
【问题描述】:

我有页面控制器,它有 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)
}

【问题讨论】:

  • 在页面控件的指定索引处更改约束常量,您希望页面控件位于顶部
  • 但我正在通过代码创建 PageControl
  • 当您到达特定索引以将您的页面控件移到顶部时,只需更新它即可。 pageControl = UIPageControl(frame: CGRect(x: 0,y: 50,width: UIScreen.main.bounds.width,height: 50))

标签: ios swift uipagecontrol


【解决方案1】:

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

试试下面的代码:

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

根据您的要求调整框架中的 Y 位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    • 1970-01-01
    相关资源
    最近更新 更多