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()
}
}