I've subclassed UIPageControl in order to have its current dot bigger.
class CustomPageControl: UIPageControl {
override var currentPage: Int {
didSet {
updateDots()
}
}
func updateDots() {
let currentDot = subviews[currentPage]
let largeScaling = CGAffineTransform(scaleX: 3, y: 3)
subviews.forEach {
// apply the large scale of newly selected dot
// restore the normal scale of previously selected dot
$0.transform = $0 == currentDot ? largeScaling : .identity
}
}
}
But the result of the transform isn't centered (the red dot should be aligned with the others):
I've tried (on iOS 12):
- changing the
frame
orcenter
ofcurrentDot
has no effect. - changing the transform to include a
translatedBy(x: CGFloat, y: CGFloat)
has no effect. changing the constraints like here is making the first dot jumping:
currentDot.translatesAutoresizingMaskIntoConstraints = false currentDot.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: 0) currentDot.centerXAnchor.constraint(equalTo: self.centerXAnchor, constant: 0)