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

Commit 4a20998

Browse files
committed
minValue now works as inteded
- Fix bugs related to inner ring drawing - Add documentation for `minValue` - Fixed any wrong comments/docs - Reran jazzy - Updated podspec
1 parent 6081933 commit 4a20998

26 files changed

+337
-110
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Version 1.7.0
2+
3+
#### Highlight: New `UICircularProgressRingView.minValue` property.
4+
5+
- Add ability to set a range of values for the ring, unlike before where only `maxValue` could be set. You can now use the new `minValue` to specify a range that the value can fall between. Read the docs to learn about any issues that may arise with setting a `value` less than `minValue`.
6+
- Fixed bugs related to how many degrees the inner ring for the progress ring draws. Everything should exact now even if not using the `fullCircle` property.
7+
- Fixed a bug which allowed setting a `value` less than zero. Read the docs to learn why this was an issue.
8+
- Refactored some unused code and tidied things up a bit
9+
- Regenerated documentation using Jazzy
10+
11+
112
# Version 1.6.2
213

314
#### Highlight: New `UICircularProgressRingDelegate` method.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2016 Luis Padron
1+
Copyright (c) 2017 Luis Padron
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

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.6.2"
5+
s.version = "1.7.0"
66
s.summary = "A highly customizable circular progress bar for iOS written in Swift 3"
77

88
s.description = <<-DESC

UICircularProgressRing/UICircularProgressRingLayer.swift

+5-8
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class UICircularProgressRingLayer: CAShapeLayer {
7171
@NSManaged var fullCircle: Bool
7272

7373
@NSManaged var value: CGFloat
74-
@NSManaged var maxValue: CGFloat
7574
@NSManaged var minValue: CGFloat
75+
@NSManaged var maxValue: CGFloat
7676

7777
@NSManaged var ringStyle: UICircularProgressRingStyle
7878
@NSManaged var patternForDashes: [CGFloat]
@@ -214,18 +214,15 @@ class UICircularProgressRingLayer: CAShapeLayer {
214214

215215
let center = CGPoint(x: bounds.midX, y: bounds.midY)
216216

217-
var innerEndAngle: CGFloat = 0.0
217+
let innerEndAngle: CGFloat
218218

219219
if fullCircle {
220-
innerEndAngle = (360.0 / maxValue)
221-
* value + startAngle
220+
innerEndAngle = (value - minValue) / maxValue * 360.0 + startAngle
222221
} else {
223222
// Calculate the center difference between the end and start angle
224-
let angleDiff: CGFloat = endAngle - startAngle
223+
let angleDiff: CGFloat = abs(endAngle - startAngle)
225224
// Calculate how much we should draw depending on the value set
226-
let arcLenPerValue = angleDiff / maxValue
227-
// The inner end angle some basic math is done
228-
innerEndAngle = arcLenPerValue * value + startAngle
225+
innerEndAngle = (value - minValue) / maxValue * angleDiff + startAngle
229226
}
230227

231228
// The radius for style 1 is set below

UICircularProgressRing/UICircularProgressRingView.swift

+35-14
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,16 @@ import UIKit
8989
// MARK: Value Properties
9090

9191
/**
92-
The value property for the progress ring. ex: (23)/100
92+
The value property for the progress ring.
9393

9494
## Important ##
9595
Default = 0
96+
97+
Must be a non-negative value. If this value falls below `minValue` it will be
98+
clamped and set equal to `minValue`.
9699

97100
This cannot be used to get the value while the ring is animating, to get
98-
current value while animating use `currentValue`
101+
current value while animating use `currentValue`.
99102

100103
The current value of the progress ring after animating, use setProgress(value:)
101104
to alter the value with the option to animate and have a completion handler.
@@ -134,27 +137,47 @@ import UIKit
134137
}
135138
}
136139
}
140+
141+
/**
142+
The minimum value for the progress ring. ex: (0) -> 100.
143+
144+
## Important ##
145+
Default = 100
146+
147+
Must be a non-negative value, the absolute value is taken when setting this property.
148+
149+
The `value` of the progress ring must NOT fall below `minValue` if it does the `value` property is clamped
150+
and will be set equal to `value`, you will receive a warning message in the console.
151+
152+
Making this value greater than
153+
154+
## Author
155+
Luis Padron
156+
*/
157+
@IBInspectable open var minValue: CGFloat = 0.0 {
158+
didSet {
159+
self.ringLayer.minValue = abs(self.minValue)
160+
}
161+
}
137162

138163
/**
139-
The max value for the progress ring. ex: 23/(100)
140-
Used to calculate amount of progress depending on self.value and self.maxValue
164+
The maximum value for the progress ring. ex: 0 -> (100)
141165

142166
## Important ##
143167
Default = 100
168+
169+
Must be a non-negative value, the absolute value is taken when setting this property.
170+
171+
Unlike the `minValue` member `value` can extend beyond `maxValue`. What happens in this case
172+
is the inner ring will do an extra loop through the outer ring, this is not noticible however.
144173

145174

146175
## Author
147176
Luis Padron
148177
*/
149178
@IBInspectable open var maxValue: CGFloat = 100.0 {
150179
didSet {
151-
self.ringLayer.maxValue = self.maxValue
152-
}
153-
}
154-
155-
@IBInspectable open var minValue: CGFloat = 0.0 {
156-
didSet {
157-
self.ringLayer.minValue = self.minValue
180+
self.ringLayer.maxValue = abs(self.maxValue)
158181
}
159182
}
160183

@@ -754,9 +777,7 @@ import UIKit
754777
self.ringLayer.font = font
755778
self.ringLayer.showFloatingPoint = showFloatingPoint
756779
self.ringLayer.decimalPlaces = decimalPlaces
757-
758-
// Sets background color to clear, this fixes a bug when placing view in
759-
// tableview cells
780+
760781
self.backgroundColor = UIColor.clear
761782
self.ringLayer.backgroundColor = UIColor.clear.cgColor
762783
}

docs/Classes.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ <h4>Declaration</h4>
114114
</section>
115115
</section>
116116
<section id="footer">
117-
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-07-03)</p>
118-
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
117+
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-08-02)</p>
118+
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.3</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
119119
</section>
120120
</article>
121121
</div>

docs/Classes/UICircularProgressRingView.html

+102-11
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,16 @@ <h3 class="section-name">Value Properties</h3>
205205
<section class="section">
206206
<div class="pointer"></div>
207207
<div class="abstract">
208-
<p>The value property for the progress ring. ex: (23)/100</p>
208+
<p>The value property for the progress ring.</p>
209209
<h2 id='important' class='heading'>Important</h2>
210210

211211
<p>Default = 0</p>
212212

213+
<p>Must be a non-negative value. If this value falls below <code><a href="../Classes/UICircularProgressRingView.html#/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)minValue">minValue</a></code> it will be
214+
clamped and set equal to <code><a href="../Classes/UICircularProgressRingView.html#/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)minValue">minValue</a></code>.</p>
215+
213216
<p>This cannot be used to get the value while the ring is animating, to get
214-
current value while animating use <code><a href="../Classes/UICircularProgressRingView.html#/s:22UICircularProgressRing0abC4ViewC12currentValue12CoreGraphics7CGFloatVSgv">currentValue</a></code></p>
217+
current value while animating use <code><a href="../Classes/UICircularProgressRingView.html#/s:22UICircularProgressRing0abC4ViewC12currentValue12CoreGraphics7CGFloatVSgv">currentValue</a></code>.</p>
215218

216219
<p>The current value of the progress ring after animating, use setProgress(value:)
217220
to alter the value with the option to animate and have a completion handler.</p>
@@ -266,6 +269,46 @@ <h4>Declaration</h4>
266269
</section>
267270
</div>
268271
</li>
272+
<li class="item">
273+
<div>
274+
<code>
275+
<a name="/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)minValue"></a>
276+
<a name="//apple_ref/swift/Property/minValue" class="dashAnchor"></a>
277+
<a class="token" href="#/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)minValue">minValue</a>
278+
</code>
279+
</div>
280+
<div class="height-container">
281+
<div class="pointer-container"></div>
282+
<section class="section">
283+
<div class="pointer"></div>
284+
<div class="abstract">
285+
<p>The minimum value for the progress ring. ex: (0) -&gt; 100.</p>
286+
<h2 id='important' class='heading'>Important</h2>
287+
288+
<p>Default = 100</p>
289+
290+
<p>Must be a non-negative value, the absolute value is taken when setting this property.</p>
291+
292+
<p>The <code><a href="../Classes/UICircularProgressRingView.html#/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)value">value</a></code> of the progress ring must NOT fall below <code>minValue</code> if it does the <code><a href="../Classes/UICircularProgressRingView.html#/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)value">value</a></code> property is clamped
293+
and will be set equal to <code><a href="../Classes/UICircularProgressRingView.html#/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)value">value</a></code>, you will receive a warning message in the console.</p>
294+
295+
<p>Making this value greater than</p>
296+
<h2 id='author' class='heading'>Author</h2>
297+
298+
<p>Luis Padron</p>
299+
300+
</div>
301+
<div class="declaration">
302+
<h4>Declaration</h4>
303+
<div class="language">
304+
<p class="aside-title">Swift</p>
305+
<pre class="highlight"><code><span class="kd">@IBInspectable</span> <span class="n">open</span> <span class="k">var</span> <span class="nv">minValue</span><span class="p">:</span> <span class="kt">CGFloat</span> <span class="o">=</span> <span class="mf">0.0</span></code></pre>
306+
307+
</div>
308+
</div>
309+
</section>
310+
</div>
311+
</li>
269312
<li class="item">
270313
<div>
271314
<code>
@@ -279,11 +322,15 @@ <h4>Declaration</h4>
279322
<section class="section">
280323
<div class="pointer"></div>
281324
<div class="abstract">
282-
<p>The max value for the progress ring. ex: 23/(100)
283-
Used to calculate amount of progress depending on self.value and self.maxValue</p>
325+
<p>The maximum value for the progress ring. ex: 0 -&gt; (100)</p>
284326
<h2 id='important' class='heading'>Important</h2>
285327

286328
<p>Default = 100</p>
329+
330+
<p>Must be a non-negative value, the absolute value is taken when setting this property.</p>
331+
332+
<p>Unlike the <code><a href="../Classes/UICircularProgressRingView.html#/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)minValue">minValue</a></code> member <code><a href="../Classes/UICircularProgressRingView.html#/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)value">value</a></code> can extend beyond <code>maxValue</code>. What happens in this case
333+
is the inner ring will do an extra loop through the outer ring, this is not noticible however.</p>
287334
<h2 id='author' class='heading'>Author</h2>
288335

289336
<p>Luis Padron</p>
@@ -293,7 +340,7 @@ <h2 id='author' class='heading'>Author</h2>
293340
<h4>Declaration</h4>
294341
<div class="language">
295342
<p class="aside-title">Swift</p>
296-
<pre class="highlight"><code><span class="kd">@IBInspectable</span> <span class="n">open</span> <span class="k">var</span> <span class="nv">maxValue</span><span class="p">:</span> <span class="kt">CGFloat</span> <span class="o">=</span> <span class="mi">100</span></code></pre>
343+
<pre class="highlight"><code><span class="kd">@IBInspectable</span> <span class="n">open</span> <span class="k">var</span> <span class="nv">maxValue</span><span class="p">:</span> <span class="kt">CGFloat</span> <span class="o">=</span> <span class="mf">100.0</span></code></pre>
297344

298345
</div>
299346
</div>
@@ -689,9 +736,9 @@ <h4>Declaration</h4>
689736
<li class="item">
690737
<div>
691738
<code>
692-
<a name="/s:22UICircularProgressRing0abC4ViewC13outerCapStyleSo06CGLineF0Ov"></a>
739+
<a name="/s:22UICircularProgressRing0abC4ViewC13outerCapStyleSC06CGLineF0Ov"></a>
693740
<a name="//apple_ref/swift/Property/outerCapStyle" class="dashAnchor"></a>
694-
<a class="token" href="#/s:22UICircularProgressRing0abC4ViewC13outerCapStyleSo06CGLineF0Ov">outerCapStyle</a>
741+
<a class="token" href="#/s:22UICircularProgressRing0abC4ViewC13outerCapStyleSC06CGLineF0Ov">outerCapStyle</a>
695742
</code>
696743
</div>
697744
<div class="height-container">
@@ -838,9 +885,9 @@ <h4>Declaration</h4>
838885
<li class="item">
839886
<div>
840887
<code>
841-
<a name="/s:22UICircularProgressRing0abC4ViewC13innerCapStyleSo06CGLineF0Ov"></a>
888+
<a name="/s:22UICircularProgressRing0abC4ViewC13innerCapStyleSC06CGLineF0Ov"></a>
842889
<a name="//apple_ref/swift/Property/innerCapStyle" class="dashAnchor"></a>
843-
<a class="token" href="#/s:22UICircularProgressRing0abC4ViewC13innerCapStyleSo06CGLineF0Ov">innerCapStyle</a>
890+
<a class="token" href="#/s:22UICircularProgressRing0abC4ViewC13innerCapStyleSC06CGLineF0Ov">innerCapStyle</a>
844891
</code>
845892
</div>
846893
<div class="height-container">
@@ -1360,6 +1407,50 @@ <h4>Declaration</h4>
13601407

13611408
</div>
13621409
</div>
1410+
<div>
1411+
<h4>Parameters</h4>
1412+
<table class="graybox">
1413+
<tbody>
1414+
<tr>
1415+
<td>
1416+
<code>
1417+
<em>newVal</em>
1418+
</code>
1419+
</td>
1420+
<td>
1421+
<div>
1422+
<p>The value to be set for the progress ring</p>
1423+
</div>
1424+
</td>
1425+
</tr>
1426+
<tr>
1427+
<td>
1428+
<code>
1429+
<em>animationDuration</em>
1430+
</code>
1431+
</td>
1432+
<td>
1433+
<div>
1434+
<p>The time interval duration for the animation</p>
1435+
</div>
1436+
</td>
1437+
</tr>
1438+
<tr>
1439+
<td>
1440+
<code>
1441+
<em>completion</em>
1442+
</code>
1443+
</td>
1444+
<td>
1445+
<div>
1446+
<p>The completion closure block that will be called when
1447+
animtion is finished (also called when animationDuration = 0), default is nil</p>
1448+
</div>
1449+
</td>
1450+
</tr>
1451+
</tbody>
1452+
</table>
1453+
</div>
13631454
</section>
13641455
</div>
13651456
</li>
@@ -1368,8 +1459,8 @@ <h4>Declaration</h4>
13681459
</section>
13691460
</section>
13701461
<section id="footer">
1371-
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-07-03)</p>
1372-
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
1462+
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-08-02)</p>
1463+
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.3</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
13731464
</section>
13741465
</article>
13751466
</div>

docs/Enums.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ <h4>Declaration</h4>
143143
</section>
144144
</section>
145145
<section id="footer">
146-
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-07-03)</p>
147-
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
146+
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-08-02)</p>
147+
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.3</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
148148
</section>
149149
</article>
150150
</div>

docs/Enums/UICircularProgressRingGradientPosition.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ <h4>Declaration</h4>
329329
</section>
330330
</section>
331331
<section id="footer">
332-
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-07-03)</p>
333-
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
332+
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-08-02)</p>
333+
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.3</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
334334
</section>
335335
</article>
336336
</div>

0 commit comments

Comments
 (0)