Increase spacing between indicator dots of UIPageControl

tbondwilkinson picture tbondwilkinson · Jun 29, 2015 · Viewed 8.5k times · Source

So I am working on customizing the UIPageControl (which Apple really doesn't make easy) and I'm wondering if there's a way to increase/decrease space between the indicator dots.

I've been using this code to get the UIPageControl

var pageControlMaybe: UIPageControl?

for (var i = 0; i < subviews.count; i++) {
    if (subviews[i] is UIPageControl) {
        pageControlMaybe = subviews[i] as? UIPageControl
        break
    }
}

But now I'm wondering if there's an easy way to change the spacing? I can resize the dots with a transform

pageControlMaybe?.transform = CGAffineTransformMakeScale(1.4, 1.4)

But this also increases the spacing between them. Ideally it would keep the dot size and just reduce the space between them.

Answer

ugur picture ugur · Sep 5, 2018

First scale pageControl

let scale: CGFloat = 1.5

pageControl.transform = CGAffineTransform.init(scaleX: scale, y: scale)

This will scale also each dot so you can scale each dot with the following code

for dot in pageControl.subviews{
    dot.transform = CGAffineTransform.init(scaleX: 1/scale, y: 1/scale)
}

A little hacky but works