Created
August 28, 2015 11:11
-
-
Save sveinhal/612241ab55bbbe8f042b to your computer and use it in GitHub Desktop.
A page control subclass with customizable dots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@IBDesignable | |
final class PageControl: UIPageControl { | |
@IBInspectable var activeImage: UIImage? | |
@IBInspectable var inactiveImage: UIImage? | |
private func updateDotImages() { | |
for (i, subview) in enumerate(subviews) { | |
if let dot = subview as? UIImageView { | |
dot.image = (i == currentPage) ? activeImage : inactiveImage | |
} | |
} | |
} | |
override var currentPage: Int { | |
didSet { | |
updateDotImages() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment