Skip to content

Commit

Permalink
Reduce redundancy drawing.
Browse files Browse the repository at this point in the history
Move Screenshots to a folder.
  • Loading branch information
Chen Yun committed Sep 24, 2017
1 parent e397ef7 commit ce5478c
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 88 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<p align="center" >
<img src="https://raw.githubusercontent.com/chenyun122/StepIndicator/master/StepIndicator.gif" alt="StepIndicator" title="StepIndicator" width="35%" height="35%">
<img src="https://raw.githubusercontent.com/chenyun122/StepIndicator/master/Screenshots/StepIndicator.gif" alt="StepIndicator" title="StepIndicator" width="35%" height="35%">
</p>

## Installation
Expand Down Expand Up @@ -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:
<p align="left" >
<img src="https://raw.githubusercontent.com/chenyun122/StepIndicator/master/Designable.gif" alt="Designable" title="Designable" width="90%" height="90%">
<img src="https://raw.githubusercontent.com/chenyun122/StepIndicator/master/Screenshots/Designable.gif" alt="Designable" title="Designable" width="90%" height="90%">
</p>
Hope you will enjoy it! Make an issue to me if you have problems or need some improvements.
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 2 additions & 2 deletions StepIndicator.podspec
Original file line number Diff line number Diff line change
@@ -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" => "[email protected]" }
s.platform = :ios, "8.0"
Expand Down
72 changes: 26 additions & 46 deletions StepIndicator/AnnularLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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") {
Expand All @@ -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()
Expand Down
48 changes: 13 additions & 35 deletions StepIndicator/HorizontalLineLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions StepIndicator/StepIndicatorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ 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]
lineLayer.frame = CGRect(x: CGFloat(i) * stepWidth + diameter + self.lineMargin * 2, y: y - 1, width: stepWidth - diameter - self.lineMargin * 2, height: 3)
lineLayer.strokeColor = self.lineColor.cgColor
lineLayer.tintColor = self.lineTintColor
lineLayer.lineWidth = self.lineStrokeWidth
lineLayer.updateStatus()
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions StepIndicatorDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yST-gL-Hd6" customClass="StepIndicatorView" customModule="StepIndicatorDemo" customModuleProvider="target">
<rect key="frame" x="56" y="114" width="263" height="80"/>
<rect key="frame" x="56" y="94" width="263" height="80"/>
<constraints>
<constraint firstAttribute="height" constant="80" id="E3e-xS-ZzW"/>
<constraint firstAttribute="width" constant="263" id="KBj-Ys-sXJ"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="numberOfSteps">
<integer key="value" value="5"/>
<integer key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="currentStep">
<integer key="value" value="0"/>
Expand All @@ -65,7 +65,7 @@
</userDefinedRuntimeAttributes>
</view>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceHorizontal="YES" pagingEnabled="YES" translatesAutoresizingMaskIntoConstraints="NO" id="MyL-yX-cNQ">
<rect key="frame" x="0.0" y="202" width="375" height="465"/>
<rect key="frame" x="0.0" y="182" width="375" height="485"/>
<connections>
<outlet property="delegate" destination="BYZ-38-t0r" id="PnJ-CX-m6O"/>
</connections>
Expand Down

0 comments on commit ce5478c

Please sign in to comment.