0

I am trying to customize the UIPageControlView. And I reference the solution from here. I rewrite the swift version. The result is the customized UIPageControl only show up when I swipe the scroll view. It always show the default appearance at first.

Here's the code.

import UIKit

class CustomizedPageControl: UIPageControl {

    // MARK: Initialization

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    func updateDots() {

        for i in 0...self.subviews.count - 1 {

            let dot = self.subviews[i]

            if i == self.currentPage {
                dot.layer.borderWidth = 0.0
                dot.layer.backgroundColor = UIColor.redColor().CGColor
            } else {
                dot.layer.borderWidth = 1.0
                dot.layer.borderColor = UIColor.grayColor().CGColor
                dot.backgroundColor = UIColor.clearColor()
            }
        }
    }

    func setCustomizedCurrentPage(page: Int) {
        super.currentPage = page
        self.updateDots()
    }
}
Community
  • 1
  • 1
Khitan
  • 11
  • 2

1 Answers1

1

change this method to this...

func updateDots() {

        for i in 0...self.subviews.count - 1 {

            let dot = self.subviews[i]
            dot.layer.borderWidth = 0.0
            dot.layer.borderColor = UIColor.grayColor().CGColor

            if i == self.currentPage {
                dot.layer.borderWidth = 0.0
                dot.layer.backgroundColor = UIColor.redColor().CGColor
            } 
        }
    }
Alexander Khitev
  • 6,417
  • 13
  • 59
  • 115
Ruchish Shah
  • 319
  • 1
  • 6