Skip to content

Instantly share code, notes, and snippets.

@bittz
Last active February 12, 2023 16:42
Show Gist options
  • Save bittz/4ab5fd793d0a18cdbfce18959174858b to your computer and use it in GitHub Desktop.
Save bittz/4ab5fd793d0a18cdbfce18959174858b to your computer and use it in GitHub Desktop.
UIPageControl with square dots having custom size (hack).
import UIKit
class QuadPageControl: UIPageControl {
override func layoutSubviews() {
super.layoutSubviews()
guard !subviews.isEmpty else { return }
let spacing: CGFloat = 3
let width: CGFloat = 15
let height = spacing
var total: CGFloat = 0
for view in subviews {
view.layer.cornerRadius = 0
view.frame = CGRect(x: total, y: frame.size.height / 2 - height / 2, width: width, height: height)
total += width + spacing
}
total -= spacing
frame.origin.x = frame.origin.x + frame.size.width / 2 - total / 2
frame.size.width = total
}
}
@Hamza9512
Copy link

Hi. I wonder if it's possible to make something like this? Thank for the QuadPageControl it helps a lot.
Screen Shot 2019-05-06 at 20 15 59

@nitinnitin12
Copy link

Hi Michał Mosiołek, thank you. This helped me alot.

@JorgeSainz
Copy link

Very usefull to have a quick customization of the shape!
Thanks you!

@pikselmutfak
Copy link

not working in iOS13.
whole layout under UIViewController.view gets broken.
only works ios < 13
any ideas.

@csprasad
Copy link

ios 13 + versions its not working "XPC Connection Interrupted"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment