diff --git a/StepIndicator/AnnularLayer.swift b/StepIndicator/AnnularLayer.swift index f916681..fd92e4f 100644 --- a/StepIndicator/AnnularLayer.swift +++ b/StepIndicator/AnnularLayer.swift @@ -15,6 +15,8 @@ class AnnularLayer: CAShapeLayer { private let flagLayer = CALayer() private let annularPath = UIBezierPath() lazy private var centerTextLayer = CATextLayer() + lazy private var titleLayer = CATextLayer() + static private let originalScale = CATransform3DMakeScale(1.0, 1.0, 1.0) static private let flagImageName = "CYStepIndicator_ic_done_white" @@ -24,6 +26,7 @@ class AnnularLayer: CAShapeLayer { // MARK: - Properties var tintColor:UIColor? var displayNumber = false + var title: String = "" var step:Int = 0 var annularDefaultColor: UIColor? @@ -85,6 +88,8 @@ class AnnularLayer: CAShapeLayer { // MARK: - Functions func updateStatus() { + // Persist title through all the states + self.drawTitle() if isFinished { self.path = nil self.drawFullCircleAnimated() @@ -165,6 +170,19 @@ class AnnularLayer: CAShapeLayer { self.addSublayer(self.centerTextLayer) } + + private func drawTitle() { + self.titleLayer.string = "\(self.title)" + self.titleLayer.frame = CGRect(x: 0, y: 0, width: 60, height: self.bounds.height) + self.titleLayer.position = CGPoint(x: self.bounds.midX, y: self.bounds.maxY * 1.75) + self.titleLayer.contentsScale = UIScreen.main.scale + self.titleLayer.foregroundColor = self.strokeColor + self.titleLayer.alignmentMode = CATextLayerAlignmentMode.center + self.titleLayer.font = UIFont.systemFont(ofSize: 10) as CFTypeRef + self.titleLayer.fontSize = 10 + + self.addSublayer(self.titleLayer) + } private func animateCenter() { self.centerCircleLayer.transform = CATransform3DMakeScale(0.8, 0.8, 1.0) diff --git a/StepIndicator/StepIndicatorView.swift b/StepIndicator/StepIndicatorView.swift index 76d1f5e..b69b1ad 100644 --- a/StepIndicator/StepIndicatorView.swift +++ b/StepIndicator/StepIndicatorView.swift @@ -39,6 +39,12 @@ public class StepIndicatorView: UIView { // MARK: - Custom properties + public var titles: [String]? { + didSet{ + self.updateSubLayers() + } + } + @IBInspectable public var numberOfSteps: Int = 5 { didSet { self.createSteps() @@ -188,6 +194,9 @@ public class StepIndicatorView: UIView { annularLayer.frame = CGRect(x: x, y: y - self.circleRadius, width: diameter, height: diameter) self.applyAnnularStyle(annularLayer: annularLayer) annularLayer.step = i + 1 + if let titles = titles { + annularLayer.title = titles[i] + } annularLayer.updateStatus() if (i < self.numberOfSteps - 1) { @@ -210,6 +219,9 @@ public class StepIndicatorView: UIView { annularLayer.frame = CGRect(x: x - self.circleRadius, y: y, width: diameter, height: diameter) self.applyAnnularStyle(annularLayer: annularLayer) annularLayer.step = i + 1 + if let titles = titles { + annularLayer.title = titles[i] + } annularLayer.updateStatus() if (i < self.numberOfSteps - 1) {