Skip to content

Commit 68eb124

Browse files
committed
Fixed #3
1 parent 50b45dc commit 68eb124

File tree

5 files changed

+92
-21
lines changed

5 files changed

+92
-21
lines changed

Example/JKSteppedProgressBar.xcodeproj/project.pbxproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
607FACCE1AFB9204008FA782 /* Resources */,
173173
C607A2CD4D69FA5D866293A2 /* [CP] Embed Pods Frameworks */,
174174
B5620B13ADE31FE3FEB49B48 /* [CP] Copy Pods Resources */,
175+
4A4947DF1F46E52400BC624C /* ShellScript */,
175176
);
176177
buildRules = (
177178
);
@@ -216,6 +217,7 @@
216217
607FACCF1AFB9204008FA782 = {
217218
CreatedOnToolsVersion = 6.3.1;
218219
LastSwiftMigration = 0810;
220+
ProvisioningStyle = Manual;
219221
};
220222
607FACE41AFB9204008FA782 = {
221223
CreatedOnToolsVersion = 6.3.1;
@@ -264,6 +266,19 @@
264266
/* End PBXResourcesBuildPhase section */
265267

266268
/* Begin PBXShellScriptBuildPhase section */
269+
4A4947DF1F46E52400BC624C /* ShellScript */ = {
270+
isa = PBXShellScriptBuildPhase;
271+
buildActionMask = 2147483647;
272+
files = (
273+
);
274+
inputPaths = (
275+
);
276+
outputPaths = (
277+
);
278+
runOnlyForDeploymentPostprocessing = 0;
279+
shellPath = /bin/sh;
280+
shellScript = "";
281+
};
267282
A5B0DAFF32F00B676FB9EB45 /* [CP] Check Pods Manifest.lock */ = {
268283
isa = PBXShellScriptBuildPhase;
269284
buildActionMask = 2147483647;
@@ -497,11 +512,13 @@
497512
buildSettings = {
498513
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
499514
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
515+
DEVELOPMENT_TEAM = "";
500516
INFOPLIST_FILE = JKSteppedProgressBar/Info.plist;
501517
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
502518
MODULE_NAME = ExampleApp;
503519
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
504520
PRODUCT_NAME = "$(TARGET_NAME)";
521+
PROVISIONING_PROFILE_SPECIFIER = "";
505522
SWIFT_VERSION = 3.0;
506523
};
507524
name = Debug;
@@ -512,11 +529,13 @@
512529
buildSettings = {
513530
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
514531
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
532+
DEVELOPMENT_TEAM = "";
515533
INFOPLIST_FILE = JKSteppedProgressBar/Info.plist;
516534
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
517535
MODULE_NAME = ExampleApp;
518536
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
519537
PRODUCT_NAME = "$(TARGET_NAME)";
538+
PROVISIONING_PROFILE_SPECIFIER = "";
520539
SWIFT_VERSION = 3.0;
521540
};
522541
name = Release;

Example/JKSteppedProgressBar.xcodeproj/xcshareddata/xcschemes/JKSteppedProgressBar-Example.xcscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
ignoresPersistentStateOnLaunch = "NO"
7575
debugDocumentVersioning = "YES"
7676
debugServiceExtension = "internal"
77-
allowLocationSimulation = "YES">
77+
allowLocationSimulation = "YES"
78+
language = "IDELaunchSchemeLanguageRightToLeftLayoutDirection">
7879
<BuildableProductRunnable
7980
runnableDebuggingMode = "0">
8081
<BuildableReference

Example/JKSteppedProgressBar/Base.lproj/Main.storyboard

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
69
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
710
</dependencies>
811
<scenes>
@@ -19,13 +22,14 @@
1922
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2023
<subviews>
2124
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Xx9-ek-0HE" customClass="SteppedProgressBar" customModule="JKSteppedProgressBar">
25+
<rect key="frame" x="20" y="28" width="335" height="85"/>
2226
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2327
<constraints>
2428
<constraint firstAttribute="height" constant="85" id="f2M-Vb-6Kw"/>
2529
</constraints>
2630
<userDefinedRuntimeAttributes>
2731
<userDefinedRuntimeAttribute type="number" keyPath="lineWidth">
28-
<real key="value" value="1"/>
32+
<real key="value" value="6"/>
2933
</userDefinedRuntimeAttribute>
3034
<userDefinedRuntimeAttribute type="color" keyPath="inactiveTextColor">
3135
<color key="value" red="0.66666666666666663" green="0.66666666666666663" blue="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
@@ -42,9 +46,13 @@
4246
<userDefinedRuntimeAttribute type="number" keyPath="currentTab">
4347
<integer key="value" value="2"/>
4448
</userDefinedRuntimeAttribute>
49+
<userDefinedRuntimeAttribute type="number" keyPath="titleOffset">
50+
<real key="value" value="2"/>
51+
</userDefinedRuntimeAttribute>
4552
</userDefinedRuntimeAttributes>
4653
</view>
4754
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="eHz-z6-WGH">
55+
<rect key="frame" x="219" y="184.5" width="30" height="30"/>
4856
<constraints>
4957
<constraint firstAttribute="height" constant="30" id="Sp4-fq-02j"/>
5058
<constraint firstAttribute="width" constant="30" id="sw2-Jo-OJQ"/>
@@ -56,6 +64,7 @@
5664
</connections>
5765
</button>
5866
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cim-ZE-7AD">
67+
<rect key="frame" x="126" y="184.5" width="30" height="30"/>
5968
<constraints>
6069
<constraint firstAttribute="height" constant="30" id="PsJ-aG-kjp"/>
6170
<constraint firstAttribute="width" constant="30" id="ugU-bC-Pae"/>
@@ -67,11 +76,13 @@
6776
</connections>
6877
</button>
6978
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Current tab" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xz1-Jy-Azt">
79+
<rect key="frame" x="144" y="156.5" width="87.5" height="20.5"/>
7080
<fontDescription key="fontDescription" type="system" pointSize="17"/>
7181
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
7282
<nil key="highlightedColor"/>
7383
</label>
7484
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WCC-jO-kGE">
85+
<rect key="frame" x="176" y="189" width="23" height="21"/>
7586
<constraints>
7687
<constraint firstAttribute="width" constant="23" id="g75-eX-p9k"/>
7788
<constraint firstAttribute="height" constant="21" id="lDt-If-hQD"/>

JKSteppedProgressBar/Classes/SteppedProgressBar.swift

100644100755
Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import UIKit
1010

1111
public let SteppedProgressBarAutomaticDimension: CGFloat = -1
1212

13+
public enum StepDrawingMode: Int {
14+
case fill
15+
case drawIndex
16+
// TODO:
17+
case image
18+
}
19+
1320
@IBDesignable
1421
open class SteppedProgressBar: UIView {
1522

@@ -39,6 +46,14 @@ open class SteppedProgressBar: UIView {
3946
}
4047
}
4148

49+
// Addressing issue #3
50+
// https://github.com/jkmathew/JKSteppedProgressBar/issues/3
51+
@IBInspectable open var titleOffset: CGFloat = 0 {
52+
didSet {
53+
self.setNeedsDisplay()
54+
}
55+
}
56+
4257
@IBInspectable open var circleSpacing: CGFloat = SteppedProgressBarAutomaticDimension {
4358
didSet {
4459
self.setNeedsDisplay()
@@ -57,6 +72,12 @@ open class SteppedProgressBar: UIView {
5772
}
5873
}
5974

75+
open var stepDrawingMode: StepDrawingMode = .drawIndex {
76+
didSet {
77+
self.setNeedsDisplay()
78+
}
79+
}
80+
6081
private var actualSpacing: CGFloat {
6182
return (circleSpacing == SteppedProgressBarAutomaticDimension) ? (frame.width - 6.0 - (CGFloat(titles.count) * circleRadius)) / CGFloat(titles.count - 1) : circleSpacing
6283
}
@@ -77,24 +98,32 @@ open class SteppedProgressBar: UIView {
7798
let context = UIGraphicsGetCurrentContext()
7899

79100
if currentTab == 0 {
80-
_ = drawTabs(from: 0, to: count, color: inactiveColor, textColor: inactiveTextColor)
101+
drawTabs(from: 0, to: count, color: inactiveColor, textColor: inactiveTextColor)
81102
}
82103
else if currentTab == count {
83-
_ = drawTabs(from: 0, to: count, color: activeColor, textColor: activeColor)
104+
drawTabs(from: 0, to: count, color: activeColor, textColor: activeColor)
84105
}
85106
else {
86-
let first = drawTabs(from: 0, to: currentTab , color: activeColor, textColor: activeColor).end
87-
let second = drawTabs(from: currentTab, to: count, color: inactiveColor, textColor: inactiveTextColor).start
107+
// Addressing issue #3
108+
// https://github.com/jkmathew/JKSteppedProgressBar/issues/3
109+
// Drawing in the order 1.inactive, 2.Line between active and inactive, 3.Active to avoid overlaping issue
110+
let end = drawTabs(from: currentTab, to: count, color: inactiveColor, textColor: inactiveTextColor).start
88111
let path = UIBezierPath()
89112
path.lineWidth = lineWidth
90113

91-
path.move(to: first)
92-
path.addLine(to: second)
114+
var start = end
115+
start.x -= actualSpacing
116+
path.move(to: start)
117+
path.addLine(to: end)
93118
context?.setStrokeColor(inactiveColor.cgColor)
94119
path.stroke()
120+
121+
drawTabs(from: 0, to: currentTab , color: activeColor, textColor: activeColor)
122+
95123
}
96124
}
97125

126+
@discardableResult
98127
func drawTabs(from begin: Int, to end: Int, color: UIColor, textColor: UIColor) -> (start: CGPoint, end: CGPoint) {
99128
let startX = bounds.midX - (CGFloat(titles.count - 1) * (actualSpacing + circleRadius) / 2.0)
100129
let x = startX + (actualSpacing + circleRadius) * CGFloat(begin)
@@ -115,7 +144,11 @@ open class SteppedProgressBar: UIView {
115144
}
116145
let context = UIGraphicsGetCurrentContext()
117146
context?.setStrokeColor(color.cgColor)
147+
context?.setFillColor(color.cgColor)
118148
path.stroke()
149+
if stepDrawingMode == .fill {
150+
path.fill()
151+
}
119152
return (start: start, end: point)
120153
}
121154

@@ -124,30 +157,33 @@ open class SteppedProgressBar: UIView {
124157
path.move(to: point)
125158
let buttonRect = circleRect(point, radius: circleRadius)
126159
let circlePath = UIBezierPath(ovalIn: buttonRect)
127-
path.append(circlePath)
128160

161+
var attributes = [NSForegroundColorAttributeName : textColor, NSParagraphStyleAttributeName: paragraphStyle]
162+
129163
//draw index
130164
let index = i
131-
let buttonTitle = "\(index + 1)"
132-
let font = UIFont.boldSystemFont(ofSize: 14.0)
133-
134-
var attributes = [NSForegroundColorAttributeName : textColor, NSParagraphStyleAttributeName: paragraphStyle, NSFontAttributeName: font]
135-
let attributedButtonTitle = NSAttributedString(string: buttonTitle, attributes: attributes)
136-
drawString(attributedButtonTitle, center: point)
165+
if stepDrawingMode == .drawIndex {
166+
let buttonTitle = "\(index + 1)"
167+
let font = UIFont.boldSystemFont(ofSize: 14.0)
168+
attributes[NSFontAttributeName] = font
169+
let attributedButtonTitle = NSAttributedString(string: buttonTitle, attributes: attributes)
170+
draw(string: attributedButtonTitle, center: point)
171+
}
172+
path.append(circlePath)
137173

138174
var titleCenter = point
139-
titleCenter.y += circleRadius * 0.75
175+
titleCenter.y += circleRadius * 0.75 + titleOffset
140176
let title = titles[index]
141177
attributes[NSFontAttributeName] = UIFont.boldSystemFont(ofSize: 12.0)
142178
let attributedTitle = NSAttributedString(string: title, attributes: attributes)
143-
drawString(attributedTitle, center: titleCenter)
179+
draw(string: attributedTitle, center: titleCenter)
144180

145181
point.x += circleRadius / 2.0
146182
path.move(to: point)
147183

148184
}
149185

150-
func drawString(_ string: NSAttributedString, center: CGPoint) {
186+
func draw(string: NSAttributedString, center: CGPoint) {
151187
var rect = string.boundingRect(with: CGSize(width: 1000, height: 1000), options: .usesFontLeading, context: nil)
152188
let size = rect.size
153189
let origin = CGPoint(x: center.x - size.width / 2.0, y: center.y - size.height / 2.0)

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ To use JKSteppedProgressBar Xcode 8.0 or later is required
1717
JKSteppedProgressBar is available through [CocoaPods](http://cocoapods.org). To install
1818
it, simply add the following line to your Podfile:
1919

20+
## TODO
21+
- [ ] Respect language direction for drawing
22+
- [ ] Add image for steps
23+
2024
```ruby
2125
pod 'JKSteppedProgressBar'
2226
```

0 commit comments

Comments
 (0)