From ce5478ccd602bf6d865e7454b10df524c6cb6acd Mon Sep 17 00:00:00 2001 From: Chen Yun Date: Sun, 24 Sep 2017 11:38:47 +0800 Subject: [PATCH] Reduce redundancy drawing. Move Screenshots to a folder. --- README.md | 4 +- Designable.gif => Screenshots/Designable.gif | Bin Screenshot.png => Screenshots/Screenshot.png | Bin .../StepIndicator.gif | Bin StepIndicator.podspec | 4 +- StepIndicator/AnnularLayer.swift | 72 +++++++----------- StepIndicator/HorizontalLineLayer.swift | 48 ++++-------- StepIndicator/StepIndicatorView.swift | 2 + StepIndicatorDemo/Base.lproj/Main.storyboard | 6 +- 9 files changed, 48 insertions(+), 88 deletions(-) rename Designable.gif => Screenshots/Designable.gif (100%) rename Screenshot.png => Screenshots/Screenshot.png (100%) rename StepIndicator.gif => Screenshots/StepIndicator.gif (100%) diff --git a/README.md b/README.md index 8a5029c..34465f1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Writen in Swift 3.2 , and Swfit 4.0 is supported. The idea and design are derived from the awesome Android version: https://github.com/badoualy/stepper-indicator

-StepIndicator +StepIndicator

## Installation @@ -63,7 +63,7 @@ Values of following properties have been set as defaults already. Change them if ### Designable in Stroyboard and Xib (Optional) After adding a `UIView` to Stroyboard or Xib, change its class to `StepIndicatorView`. Then you are able to config it as this demonstration:

-Designable +Designable

Hope you will enjoy it! Make an issue to me if you have problems or need some improvements. diff --git a/Designable.gif b/Screenshots/Designable.gif similarity index 100% rename from Designable.gif rename to Screenshots/Designable.gif diff --git a/Screenshot.png b/Screenshots/Screenshot.png similarity index 100% rename from Screenshot.png rename to Screenshots/Screenshot.png diff --git a/StepIndicator.gif b/Screenshots/StepIndicator.gif similarity index 100% rename from StepIndicator.gif rename to Screenshots/StepIndicator.gif diff --git a/StepIndicator.podspec b/StepIndicator.podspec index 464620d..f328687 100644 --- a/StepIndicator.podspec +++ b/StepIndicator.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = "StepIndicator" - s.version = "1.0.2" + s.version = "1.0.3" s.summary = "An iOS Step Indicator Library." s.description = <<-DESC StepIndicator is an iOS library that indicates steps in an animated way. DESC s.homepage = "https://github.com/chenyun122/StepIndicator" - s.screenshots = "https://raw.githubusercontent.com/chenyun122/StepIndicator/master/Screenshot.png" + s.screenshots = "https://raw.githubusercontent.com/chenyun122/StepIndicator/master/Screenshots/Screenshot.png" s.license = "MIT" s.author = { "Yun Chen" => "chenyun122@gmail.com" } s.platform = :ios, "8.0" diff --git a/StepIndicator/AnnularLayer.swift b/StepIndicator/AnnularLayer.swift index 262b1f9..fe07c81 100644 --- a/StepIndicator/AnnularLayer.swift +++ b/StepIndicator/AnnularLayer.swift @@ -10,15 +10,31 @@ import UIKit class AnnularLayer: CAShapeLayer { - let fullCircleLayer = CAShapeLayer() - let centerLayer = CAShapeLayer() - let flagLayer = CALayer() - let annularPath = UIBezierPath() + private let fullCircleLayer = CAShapeLayer() + private let centerLayer = CAShapeLayer() + private let flagLayer = CALayer() + private let annularPath = UIBezierPath() - static let originalScale = CATransform3DMakeScale(1.0, 1.0, 1.0) - static let flagImageName = "CYStepIndicator_ic_done_white" - static var flagCGImage:CGImage? + static private let originalScale = CATransform3DMakeScale(1.0, 1.0, 1.0) + static private let flagImageName = "CYStepIndicator_ic_done_white" + static private var flagCGImage:CGImage? + + // MARK: - Properties + var tintColor:UIColor? + var isCurrent:Bool = false { + didSet{ + self.updateStatus() + } + } + var isFinished:Bool = false { + didSet{ + self.updateStatus() + } + } + + + //MARK: - Initialization override init() { super.init() @@ -27,6 +43,8 @@ class AnnularLayer: CAShapeLayer { if AnnularLayer.flagCGImage == nil { var flagImage = UIImage(named: AnnularLayer.flagImageName) + + //For Pods bundle if flagImage == nil { let bundle = Bundle(for: AnnularLayer.self) if let url = bundle.url(forResource: "StepIndicator", withExtension: "bundle") { @@ -46,46 +64,8 @@ class AnnularLayer: CAShapeLayer { } - // MARK: - Properties - override var frame: CGRect { - didSet{ - self.updateStatus() - } - } - - override var lineWidth: CGFloat { - didSet{ - self.updateStatus() - } - } - - override var strokeColor: CGColor? { - didSet { - self.updateStatus() - } - } - - var tintColor:UIColor? { - didSet { - self.updateStatus() - } - } - - var isCurrent:Bool = false { - didSet{ - self.updateStatus() - } - } - - var isFinished:Bool = false { - didSet{ - self.updateStatus() - } - } - - // MARK: - Functions - private func updateStatus() { + func updateStatus() { if isFinished { self.path = nil self.drawFullCircleAnimated() diff --git a/StepIndicator/HorizontalLineLayer.swift b/StepIndicator/HorizontalLineLayer.swift index 2e01b75..3d863b1 100644 --- a/StepIndicator/HorizontalLineLayer.swift +++ b/StepIndicator/HorizontalLineLayer.swift @@ -10,54 +10,32 @@ import UIKit class HorizontalLineLayer: CAShapeLayer { - let tintLineLayer = CAShapeLayer() - - override init() { - super.init() - - self.fillColor = UIColor.clear.cgColor - self.lineWidth = 2 - } - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - + private let tintLineLayer = CAShapeLayer() // MARK: - Properties - override var frame: CGRect { - didSet{ - self.updateStatus() - } - } - - override var lineWidth: CGFloat { + var tintColor:UIColor? + var isFinished:Bool = false { didSet{ self.updateStatus() } } - override var strokeColor: CGColor? { - didSet { - self.updateStatus() - } - } - var tintColor:UIColor? { - didSet { - self.updateStatus() - } + //MARK: - Initialization + override init() { + super.init() + + self.fillColor = UIColor.clear.cgColor + self.lineWidth = 2 } - var isFinished:Bool = false { - didSet{ - self.updateStatus() - } + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) } - + // MARK: - Functions - private func updateStatus() { + func updateStatus() { self.drawLinePath() if isFinished { self.drawTintLineAnimated() diff --git a/StepIndicator/StepIndicatorView.swift b/StepIndicator/StepIndicatorView.swift index 52b7f6a..21fd7e9 100644 --- a/StepIndicator/StepIndicatorView.swift +++ b/StepIndicator/StepIndicatorView.swift @@ -133,6 +133,7 @@ public class StepIndicatorView: UIView { annularLayer.strokeColor = self.circleColor.cgColor annularLayer.tintColor = self.circleTintColor annularLayer.lineWidth = self.circleStrokeWidth + annularLayer.updateStatus() if (i < self.numberOfSteps - 1) { let lineLayer = self.horizontalLineLayers[i] @@ -140,6 +141,7 @@ public class StepIndicatorView: UIView { lineLayer.strokeColor = self.lineColor.cgColor lineLayer.tintColor = self.lineTintColor lineLayer.lineWidth = self.lineStrokeWidth + lineLayer.updateStatus() } } } diff --git a/StepIndicatorDemo/Base.lproj/Main.storyboard b/StepIndicatorDemo/Base.lproj/Main.storyboard index 9b35784..9b100ca 100644 --- a/StepIndicatorDemo/Base.lproj/Main.storyboard +++ b/StepIndicatorDemo/Base.lproj/Main.storyboard @@ -38,14 +38,14 @@ - + - + @@ -65,7 +65,7 @@ - +