Increase the size of the indicator in UIPageViewController's UIPageControl

只谈情不闲聊 提交于 2019-11-28 20:27:11

Scaling the page control will scale the dots, but will also scale the spacing in between them.

pageControl.transform = CGAffineTransform(scaleX: 2, y: 2)

If you want to keep the same spacing between dots, you'll need to transform the dots individually:

pageControl.subviews.forEach {
    $0.transform = CGAffineTransform(scaleX: 2, y: 2)
}

However, if you do this in viewDidLoad, the transform has been reset by the time the view appears, so you should do this in viewDidLayoutSubviews

override func viewDidLayoutSubviews() {
    pageControl.subviews.forEach {
        $0.transform = CGAffineTransform(scaleX: 2, y: 2)
    }
}

You can use an UIPageControl and scale it like this :

@IBOutlet weak var pageControl: UIPageControl!

 override func viewDidLoad() {
    super.viewDidLoad()
    pageControl.transform = CGAffineTransform(scaleX: 2, y: 2); //set value here
}

The problem with that is that you space between your dots will be increase too. If you want to have an accurate design with your dot you have to use 3party controls : https://www.cocoacontrols.com/

For swift 2.0 to increase or decrease size of pageControl Indicator

self.pageControl.transform = CGAffineTransformMakeScale(0.8, 0.8)

OR

self.pageControl.transform = CGAffineTransformMakeScale(1.3, 1.3)

Firstly, create an uiPageControl object inside inside viewDidLoad() and then set it's y position as per your requirement then apply required scale using CAAffiniteTransform as below:

        var pageControl = UIPageControl()
        pageControl.pageIndicatorTintColor = UIColor.gray
        pageControl.currentPageIndicatorTintColor = UIColor.yellow

        pageControl.transform = CGAffineTransform(scaleX: 1.3, y: 1.3) // set dot scale of pageControl

        pageControl.backgroundColor = UIColor.darkGray
        pageControl.numberOfPages = 3
        pageControl.center = self.view.center 
        self.view.addSubview(pageControl) // add pageControl to view

        pageControl.layer.position.y = self.view.frame.height - 100; // y position of the pageControl

Swift 4, 4.2 and 5

First create an outlet of page control

@IBOutlet weak var pageControl: UIPageControl!

If you want to keep the original spacing.

override func viewDidLayoutSubviews() {
        pageControl.transform = CGAffineTransform(scaleX: 2, y: 2)
}

If you don't want to keep the original spacing.

override func viewDidLayoutSubviews() {
        pageControl.subviews.forEach {
            $0.transform = CGAffineTransform(scaleX: 2, y: 2)
        }
}

Add an extension to the page controller

extension UIPageControl {
    func customPageControl(dotWidth: CGFloat) {
        for (pageIndex, dotView) in self.subviews.enumerated() {
            dotView.frame.size = CGSize.init(width: dotWidth, height: dotWidth)
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!