Scaling current dot of UIPageControl and keeping it centered

后端 未结 2 1459
遇见更好的自我
遇见更好的自我 2021-01-21 14:37

I\'ve subclassed UIPageControl in order to have its current dot bigger.

class CustomPageControl: UIPageControl {
    override var currentPage: Int {
        didS         


        
2条回答
  •  走了就别回头了
    2021-01-21 15:19

    I tried the solution proposed by Cœur in Swift 5 and Xcode 11 and it works fine with a few notes:

    • The PageControl element in IB/Storyboard has to be positioned with constraints.
    • The dots are slightly off-center but it can be quickly fixed by changing the constant of the last constraint to systemDotDistance * ( CGFloat($0.offset) - (halfCount - 0.5)).
    • If the updateConstraints override is never called, you might need to call self.view.setNeedsUpdateConstraints() in the view controller.

提交回复
热议问题