Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase spacing between indicator dots of UIPageControl

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.

like image 695
tbondwilkinson Avatar asked Jun 29 '15 20:06

tbondwilkinson


1 Answers

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

like image 98
ugur Avatar answered Oct 17 '22 01:10

ugur