Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Commit 214aebf

Browse files
Luis PadronLuis Padron
Luis Padron
authored and
Luis Padron
committed
Version 2.0
- Add back default to nil for completion handler - Fix inStyle not being set properly - Added basic tests - Minor refactoring - Remove private access, made it internal
1 parent 0f2cf41 commit 214aebf

16 files changed

+151
-50
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Version 1.2.0
2+
3+
4+
- Default completion handler to nil for `setProgress(:)`
5+
- Fix issue with module version number, now actually supports __iOS 8__
6+
- Added some basic tests for right now
7+
- Refactor some comments
8+
- Remove `private` access, set to `internal` for unit testing
9+
- Fix default with inCapStyle being sett to wrong value
10+
111
# Version 1.1.9
212

313

UICircularProgressRing.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Pod::Spec.new do |s|
33

44
s.name = "UICircularProgressRing"
5-
s.version = "1.1.9"
5+
s.version = "1.2.0"
66
s.summary = "A highly customizable circular progress bar for iOS written in Swift 3"
77

88
s.description = <<-DESC

UICircularProgressRing.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@
348348
DYLIB_INSTALL_NAME_BASE = "@rpath";
349349
INFOPLIST_FILE = UICircularProgressRing/Info.plist;
350350
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
351-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
351+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
352352
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
353353
PRODUCT_BUNDLE_IDENTIFIER = com.luispadron.UICircularProgressRing;
354354
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -370,7 +370,7 @@
370370
DYLIB_INSTALL_NAME_BASE = "@rpath";
371371
INFOPLIST_FILE = UICircularProgressRing/Info.plist;
372372
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
373-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
373+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
374374
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
375375
PRODUCT_BUNDLE_IDENTIFIER = com.luispadron.UICircularProgressRing;
376376
PRODUCT_NAME = "$(TARGET_NAME)";

UICircularProgressRing/UICircularProgressRingView.swift

+13-15
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ import UIKit
6666
## Important ##
6767
Default = 0
6868

69-
Recommended to assign value using setProgress(_:) instead as you have more control over what happens
70-
This is public simply for storyboard support
69+
The current value of the progress ring, use setProgress(value:) to alter the value with the option
70+
to animate and have a completion handler.
7171

7272
## Author:
7373
Luis Padron
@@ -164,7 +164,7 @@ import UIKit
164164
I.e: 90 degrees is at the bottom and 270 degrees is at the top
165165

166166
## Important ##
167-
Default = 0 (degrees)
167+
Default = 360 (degrees)
168168

169169
Values should be in degrees (they're converted to radians internally)
170170

@@ -244,13 +244,13 @@ import UIKit
244244

245245
/**
246246

247-
A private outerRingCapStyle variable, this is set whenever the
247+
A internal outerRingCapStyle variable, this is set whenever the
248248
IB compatible variable above is set.
249249

250250
Basically in here because IB doesn't support CGLineCap selection.
251251

252252
*/
253-
private var outStyle: CGLineCap = .butt
253+
internal var outStyle: CGLineCap = .butt
254254

255255
// MARK: Inner Ring properties
256256

@@ -341,13 +341,13 @@ import UIKit
341341

342342
/**
343343

344-
A private innerRingCapStyle variable, this is set whenever the
344+
A internal innerRingCapStyle variable, this is set whenever the
345345
IB compatible variable above is set.
346346

347347
Basically in here because IB doesn't support CGLineCap selection.
348348

349349
*/
350-
private var inStyle: CGLineCap = .butt
350+
internal var inStyle: CGLineCap = .round
351351

352352
// MARK: Label
353353

@@ -530,7 +530,7 @@ import UIKit
530530
*/
531531
override public init(frame: CGRect) {
532532
super.init(frame: frame)
533-
// Call the private initializer
533+
// Call the internal initializer
534534
initialize()
535535
}
536536

@@ -539,7 +539,7 @@ import UIKit
539539
*/
540540
required public init?(coder aDecoder: NSCoder) {
541541
super.init(coder: aDecoder)
542-
// Call the private initializer
542+
// Call the internal initializer
543543
initialize()
544544
}
545545

@@ -548,7 +548,7 @@ import UIKit
548548
For some reason didSet doesnt get called during initializing, so
549549
has to be done manually in here or else nothing would be drawn.
550550
*/
551-
private func initialize() {
551+
internal func initialize() {
552552
// Helps with pixelation and blurriness on retina devices
553553
self.layer.contentsScale = UIScreen.main.scale
554554
self.layer.shouldRasterize = true
@@ -589,7 +589,7 @@ import UIKit
589589
/**
590590
Typealias for the setProgress(:) method closure
591591
*/
592-
public typealias ProgressCompletion = (() -> Void)?
592+
public typealias ProgressCompletion = (() -> Void)
593593

594594
/**
595595
Sets the current value for the progress ring
@@ -604,7 +604,7 @@ import UIKit
604604
## Author:
605605
Luis Padron
606606
*/
607-
public func setProgress(value: CGFloat, animationDuration: TimeInterval, completion: ProgressCompletion = nil) {
607+
public func setProgress(value: CGFloat, animationDuration: TimeInterval, completion: ProgressCompletion? = nil) {
608608
// Only animte if duration sent is greater than zero
609609
self.ringLayer.animated = animationDuration > 0
610610
self.ringLayer.animationDuration = animationDuration
@@ -613,9 +613,7 @@ import UIKit
613613
CATransaction.setCompletionBlock {
614614
// Call the closure block
615615
self.delegate?.finishedUpdatingProgress(forRing: self)
616-
if let comp = completion {
617-
comp()
618-
}
616+
completion?()
619617
}
620618
self.value = value
621619
self.ringLayer.value = value

UICircularProgressRingTests/UICircularProgressRingTests.swift

+105-11
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,120 @@ import XCTest
1111

1212
class UICircularProgressRingTests: XCTestCase {
1313

14+
var progressRing: UICircularProgressRingView!
15+
1416
override func setUp() {
1517
super.setUp()
16-
// Put setup code here. This method is called before the invocation of each test method in the class.
18+
19+
progressRing = UICircularProgressRingView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
1720
}
1821

1922
override func tearDown() {
20-
// Put teardown code here. This method is called after the invocation of each test method in the class.
2123
super.tearDown()
24+
25+
progressRing = nil
2226
}
2327

24-
func testExample() {
25-
// This is an example of a functional test case.
26-
// Use XCTAssert and related functions to verify your tests produce the correct results.
27-
}
28-
29-
func testPerformanceExample() {
30-
// This is an example of a performance test case.
31-
self.measure {
32-
// Put the code you want to measure the time of here.
28+
func testApiAndAnimations() {
29+
30+
progressRing.setProgress(value: 20, animationDuration: 2) {
31+
XCTAssertEqual(self.progressRing.value, 20)
3332
}
33+
34+
progressRing.setProgress(value: 23.1, animationDuration: 0)
35+
XCTAssertEqual(progressRing.value, 23.1)
36+
37+
progressRing.setProgress(value: 17.9, animationDuration: 0, completion: nil)
38+
XCTAssertEqual(progressRing.value, 17.9)
39+
40+
progressRing.setProgress(value: 100, animationDuration: 2) {
41+
XCTAssertEqual(self.progressRing.value, 100) // Value should be set
42+
XCTAssertEqual(self.progressRing.isAnimating, false) // No longer animating, this should be false
43+
self.progressRing.setProgress(value: 25.32, animationDuration: 3, completion: {
44+
XCTAssertEqual(self.progressRing.value, 25.32) // Value set
45+
XCTAssertEqual(self.progressRing.isAnimating, false) // No longer animating, this should be false
46+
})
47+
}
48+
49+
// Since animation takes 2 seconds and happens concurrently, isAnimating should be true here
50+
XCTAssertEqual(progressRing.isAnimating, true)
3451
}
3552

53+
func testDefaultsAndSetters() {
54+
// Check the defaults for the view, change them, then make sure they changed
55+
XCTAssertNil(progressRing.delegate)
56+
57+
XCTAssertEqual(progressRing.value, 0)
58+
progressRing.value = 50
59+
XCTAssertEqual(progressRing.value, 50)
60+
61+
XCTAssertEqual(progressRing.maxValue, 100)
62+
progressRing.maxValue = 200
63+
XCTAssertEqual(progressRing.maxValue, 200)
64+
65+
XCTAssertEqual(progressRing.viewStyle, 1)
66+
progressRing.viewStyle = 2
67+
XCTAssertEqual(progressRing.viewStyle, 2)
68+
69+
XCTAssertEqual(progressRing.patternForDashes, [7.0, 7.0])
70+
progressRing.patternForDashes = [6.0, 5.0]
71+
XCTAssertEqual(progressRing.patternForDashes, [6.0, 5.0])
72+
73+
XCTAssertEqual(progressRing.startAngle, 0)
74+
progressRing.startAngle = 90
75+
XCTAssertEqual(progressRing.startAngle, 90)
76+
77+
XCTAssertEqual(progressRing.endAngle, 360)
78+
progressRing.endAngle = 180
79+
XCTAssertEqual(progressRing.endAngle, 180)
80+
81+
82+
XCTAssertEqual(progressRing.outerRingWidth, 10)
83+
progressRing.outerRingWidth = 5
84+
XCTAssertEqual(progressRing.outerRingWidth, 5)
85+
86+
XCTAssertEqual(progressRing.outerRingColor, UIColor.gray)
87+
progressRing.outerRingColor = UIColor.red
88+
XCTAssertEqual(progressRing.outerRingColor, UIColor.red)
89+
90+
XCTAssertEqual(progressRing.outerRingCapStyle, 1)
91+
XCTAssertEqual(progressRing.outStyle, .butt)
92+
progressRing.outerRingCapStyle = 2
93+
XCTAssertEqual(progressRing.outerRingCapStyle, 2)
94+
XCTAssertEqual(progressRing.outStyle, .round)
95+
96+
XCTAssertEqual(progressRing.innerRingWidth, 5.0)
97+
progressRing.innerRingWidth = 10.0
98+
XCTAssertEqual(progressRing.innerRingWidth, 10.0)
99+
100+
XCTAssertEqual(progressRing.innerRingColor, UIColor.blue)
101+
progressRing.innerRingColor = UIColor.green
102+
XCTAssertEqual(progressRing.innerRingColor, UIColor.green)
103+
104+
XCTAssertEqual(progressRing.innerRingSpacing, 1)
105+
progressRing.innerRingSpacing = 2
106+
XCTAssertEqual(progressRing.innerRingSpacing, 2)
107+
108+
XCTAssertEqual(progressRing.innerRingCapStyle, 2)
109+
XCTAssertEqual(progressRing.inStyle, .round)
110+
progressRing.innerRingCapStyle = 3
111+
XCTAssertEqual(progressRing.innerRingCapStyle, 3)
112+
XCTAssertEqual(progressRing.inStyle, .square)
113+
114+
XCTAssertEqual(progressRing.shouldShowValueText, true)
115+
progressRing.shouldShowValueText = false
116+
XCTAssertEqual(progressRing.shouldShowValueText, false)
117+
118+
XCTAssertEqual(progressRing.fontColor, UIColor.black)
119+
progressRing.fontColor = UIColor.darkText
120+
XCTAssertEqual(progressRing.fontColor, UIColor.darkText)
121+
122+
XCTAssertEqual(progressRing.fontSize, 18)
123+
progressRing.fontSize = 20
124+
XCTAssertEqual(progressRing.fontSize, 20)
125+
126+
XCTAssertEqual(progressRing.animationStyle, kCAMediaTimingFunctionEaseIn)
127+
progressRing.animationStyle = kCAMediaTimingFunctionLinear
128+
XCTAssertEqual(progressRing.animationStyle, kCAMediaTimingFunctionLinear)
129+
}
36130
}

docs/Classes.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ <h4>Declaration</h4>
123123
</article>
124124
</div>
125125
<section class="footer">
126-
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-20)</p>
126+
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-27)</p>
127127
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
128128
</section>
129129
</body>

docs/Classes/UICircularProgressRingView.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ <h3 class="section-name">Delegate</h3>
121121
<h4>Declaration</h4>
122122
<div class="language">
123123
<p class="aside-title">Swift</p>
124-
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">typealias</span> <span class="kt">ProgressCompletion</span> <span class="o">=</span> <span class="p">(()</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)?</span></code></pre>
124+
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">typealias</span> <span class="kt">ProgressCompletion</span> <span class="o">=</span> <span class="p">(()</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>
125125

126126
</div>
127127
</div>
@@ -196,8 +196,8 @@ <h3 class="section-name">Value Properties</h3>
196196

197197
<p>Default = 0</p>
198198

199-
<p>Recommended to assign value using setProgress(_:) instead as you have more control over what happens
200-
This is public simply for storyboard support</p>
199+
<p>The current value of the progress ring, use setProgress(value:) to alter the value with the option
200+
to animate and have a completion handler.</p>
201201

202202
<p><a href='#author' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='author'>Author:</h2></p>
203203

@@ -403,7 +403,7 @@ <h4>Declaration</h4>
403403

404404
<p><a href='#important' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='important'>Important</h2></p>
405405

406-
<p>Default = 0 (degrees)</p>
406+
<p>Default = 360 (degrees)</p>
407407

408408
<p>Values should be in degrees (they&rsquo;re converted to radians internally)</p>
409409

@@ -1233,7 +1233,7 @@ <h4>Declaration</h4>
12331233
<h4>Declaration</h4>
12341234
<div class="language">
12351235
<p class="aside-title">Swift</p>
1236-
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">setProgress</span><span class="p">(</span><span class="nv">value</span><span class="p">:</span> <span class="kt">CGFloat</span><span class="p">,</span> <span class="nv">animationDuration</span><span class="p">:</span> <span class="kt">TimeInterval</span><span class="p">,</span> <span class="nv">completion</span><span class="p">:</span> <span class="kt"><a href="../Classes/UICircularProgressRingView.html#/s:C22UICircularProgressRing26UICircularProgressRingView18ProgressCompletion">ProgressCompletion</a></span><span class="p">)</span></code></pre>
1236+
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">setProgress</span><span class="p">(</span><span class="nv">value</span><span class="p">:</span> <span class="kt">CGFloat</span><span class="p">,</span> <span class="nv">animationDuration</span><span class="p">:</span> <span class="kt">TimeInterval</span><span class="p">,</span> <span class="nv">completion</span><span class="p">:</span> <span class="kt"><a href="../Classes/UICircularProgressRingView.html#/s:C22UICircularProgressRing26UICircularProgressRingView18ProgressCompletion">ProgressCompletion</a></span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span></code></pre>
12371237

12381238
</div>
12391239
</div>
@@ -1294,7 +1294,7 @@ <h4>Parameters</h4>
12941294
</article>
12951295
</div>
12961296
<section class="footer">
1297-
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-20)</p>
1297+
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-27)</p>
12981298
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
12991299
</section>
13001300
</body>

docs/Protocols.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ <h4>Declaration</h4>
119119
</article>
120120
</div>
121121
<section class="footer">
122-
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-20)</p>
122+
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-27)</p>
123123
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
124124
</section>
125125
</body>

docs/Protocols/UICircularProgressRingDelegate.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ <h4>Parameters</h4>
151151
</article>
152152
</div>
153153
<section class="footer">
154-
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-20)</p>
154+
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-27)</p>
155155
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
156156
</section>
157157
</body>

docs/docsets/UICircularProgressRing.docset/Contents/Resources/Documents/Classes.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ <h4>Declaration</h4>
123123
</article>
124124
</div>
125125
<section class="footer">
126-
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-20)</p>
126+
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-27)</p>
127127
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
128128
</section>
129129
</body>

0 commit comments

Comments
 (0)