如何更改UIPageViewController的页面指示符大小

时间:2016-04-28 10:33:59

标签: swift size uipageviewcontroller

我已经使用此blog

创建了UIPageViewController教程

现在我需要更改页面指示框的大小。 我已经尝试更改控制器的帧大小但没有成功

以下是我正在使用的代码

private func createPageViewController() {
    let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
    let pageController = mainStoryboard.instantiateViewControllerWithIdentifier("ImagesPagerViewController") as! UIPageViewController
    pageController.dataSource = self


    if contentImages.count > 0 {
        let firstController = getItemController(0)!
        let startingViewControllers: NSArray = [firstController]
        pageController.setViewControllers(startingViewControllers as? [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
    }


    pageViewController = pageController
    addChildViewController(pageViewController!)
    self.view.addSubview(pageViewController!.view)
    pageViewController!.didMoveToParentViewController(self)
}

//Setting appearance globally
private func setupPageControl() {
    let appearance = UIPageControl.appearance()
    appearance.pageIndicatorTintColor = UIColor.grayColor()
    appearance.currentPageIndicatorTintColor = UIColor.whiteColor()
    appearance.backgroundColor = UIColor.redColor()
}

有解决办法吗?

2 个答案:

答案 0 :(得分:0)

你无法改变嵌入式UIPageControl的位置,但你可以创建自己的UIPageControl并获得对它的完全控制,注意我在下面的例子中使用SnapKit来设置约束,你可以用你喜欢的替换它技术(示例中的约束值是伪代码)

let pageControl = UIPageControl()
parentView.addSubview(pageControl)
pageControl.snp_makeConstraints { (make) -> Void in
        make.width.equalTo(yourdesiredWidth)
        make.height.equalTo(yourdesiredHeight)
        make.bottom.equalTo(yourBottom)
        make.centerX.equalTo(yourcenter)
    }
    pageControl.numberOfPages = N 
    pageControl.currentPage = 0

答案 1 :(得分:0)

在页面底部有github link project

您可以根据需要简单地转到故事板并自定义UIPageControl:

enter image description here

并更改框架(和约束..):

enter image description here