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

Commit

Permalink
minValue now works as inteded
Browse files Browse the repository at this point in the history
- Fix bugs related to inner ring drawing
- Add documentation for `minValue`
- Fixed any wrong comments/docs
- Reran jazzy
- Updated podspec
  • Loading branch information
luispadron committed Aug 3, 2017
1 parent 6081933 commit 4a20998
Show file tree
Hide file tree
Showing 26 changed files with 337 additions and 110 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Version 1.7.0

#### Highlight: New `UICircularProgressRingView.minValue` property.

- 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`.
- 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.
- Fixed a bug which allowed setting a `value` less than zero. Read the docs to learn why this was an issue.
- Refactored some unused code and tidied things up a bit
- Regenerated documentation using Jazzy


# Version 1.6.2

#### Highlight: New `UICircularProgressRingDelegate` method.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016 Luis Padron
Copyright (c) 2017 Luis Padron

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:

Expand Down
2 changes: 1 addition & 1 deletion UICircularProgressRing.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |s|

s.name = "UICircularProgressRing"
s.version = "1.6.2"
s.version = "1.7.0"
s.summary = "A highly customizable circular progress bar for iOS written in Swift 3"

s.description = <<-DESC
Expand Down
13 changes: 5 additions & 8 deletions UICircularProgressRing/UICircularProgressRingLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class UICircularProgressRingLayer: CAShapeLayer {
@NSManaged var fullCircle: Bool

@NSManaged var value: CGFloat
@NSManaged var maxValue: CGFloat
@NSManaged var minValue: CGFloat
@NSManaged var maxValue: CGFloat

@NSManaged var ringStyle: UICircularProgressRingStyle
@NSManaged var patternForDashes: [CGFloat]
Expand Down Expand Up @@ -214,18 +214,15 @@ class UICircularProgressRingLayer: CAShapeLayer {

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

var innerEndAngle: CGFloat = 0.0
let innerEndAngle: CGFloat

if fullCircle {
innerEndAngle = (360.0 / maxValue)
* value + startAngle
innerEndAngle = (value - minValue) / maxValue * 360.0 + startAngle
} else {
// Calculate the center difference between the end and start angle
let angleDiff: CGFloat = endAngle - startAngle
let angleDiff: CGFloat = abs(endAngle - startAngle)
// Calculate how much we should draw depending on the value set
let arcLenPerValue = angleDiff / maxValue
// The inner end angle some basic math is done
innerEndAngle = arcLenPerValue * value + startAngle
innerEndAngle = (value - minValue) / maxValue * angleDiff + startAngle
}

// The radius for style 1 is set below
Expand Down
49 changes: 35 additions & 14 deletions UICircularProgressRing/UICircularProgressRingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ import UIKit
// MARK: Value Properties

/**
The value property for the progress ring. ex: (23)/100
The value property for the progress ring.
## Important ##
Default = 0
Must be a non-negative value. If this value falls below `minValue` it will be
clamped and set equal to `minValue`.
This cannot be used to get the value while the ring is animating, to get
current value while animating use `currentValue`
current value while animating use `currentValue`.
The current value of the progress ring after animating, use setProgress(value:)
to alter the value with the option to animate and have a completion handler.
Expand Down Expand Up @@ -134,27 +137,47 @@ import UIKit
}
}
}

/**
The minimum value for the progress ring. ex: (0) -> 100.
## Important ##
Default = 100
Must be a non-negative value, the absolute value is taken when setting this property.
The `value` of the progress ring must NOT fall below `minValue` if it does the `value` property is clamped
and will be set equal to `value`, you will receive a warning message in the console.
Making this value greater than
## Author
Luis Padron
*/
@IBInspectable open var minValue: CGFloat = 0.0 {
didSet {
self.ringLayer.minValue = abs(self.minValue)
}
}

/**
The max value for the progress ring. ex: 23/(100)
Used to calculate amount of progress depending on self.value and self.maxValue
The maximum value for the progress ring. ex: 0 -> (100)
## Important ##
Default = 100
Must be a non-negative value, the absolute value is taken when setting this property.
Unlike the `minValue` member `value` can extend beyond `maxValue`. What happens in this case
is the inner ring will do an extra loop through the outer ring, this is not noticible however.
## Author
Luis Padron
*/
@IBInspectable open var maxValue: CGFloat = 100.0 {
didSet {
self.ringLayer.maxValue = self.maxValue
}
}

@IBInspectable open var minValue: CGFloat = 0.0 {
didSet {
self.ringLayer.minValue = self.minValue
self.ringLayer.maxValue = abs(self.maxValue)
}
}

Expand Down Expand Up @@ -754,9 +777,7 @@ import UIKit
self.ringLayer.font = font
self.ringLayer.showFloatingPoint = showFloatingPoint
self.ringLayer.decimalPlaces = decimalPlaces

// Sets background color to clear, this fixes a bug when placing view in
// tableview cells

self.backgroundColor = UIColor.clear
self.ringLayer.backgroundColor = UIColor.clear.cgColor
}
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<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>
<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>
<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>
<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>
</section>
</article>
</div>
Expand Down
113 changes: 102 additions & 11 deletions docs/Classes/UICircularProgressRingView.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,16 @@ <h3 class="section-name">Value Properties</h3>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The value property for the progress ring. ex: (23)/100</p>
<p>The value property for the progress ring.</p>
<h2 id='important' class='heading'>Important</h2>

<p>Default = 0</p>

<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
clamped and set equal to <code><a href="../Classes/UICircularProgressRingView.html#/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)minValue">minValue</a></code>.</p>

<p>This cannot be used to get the value while the ring is animating, to get
current value while animating use <code><a href="../Classes/UICircularProgressRingView.html#/s:22UICircularProgressRing0abC4ViewC12currentValue12CoreGraphics7CGFloatVSgv">currentValue</a></code></p>
current value while animating use <code><a href="../Classes/UICircularProgressRingView.html#/s:22UICircularProgressRing0abC4ViewC12currentValue12CoreGraphics7CGFloatVSgv">currentValue</a></code>.</p>

<p>The current value of the progress ring after animating, use setProgress(value:)
to alter the value with the option to animate and have a completion handler.</p>
Expand Down Expand Up @@ -266,6 +269,46 @@ <h4>Declaration</h4>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)minValue"></a>
<a name="//apple_ref/swift/Property/minValue" class="dashAnchor"></a>
<a class="token" href="#/c:@M@UICircularProgressRing@objc(cs)UICircularProgressRingView(py)minValue">minValue</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The minimum value for the progress ring. ex: (0) -&gt; 100.</p>
<h2 id='important' class='heading'>Important</h2>

<p>Default = 100</p>

<p>Must be a non-negative value, the absolute value is taken when setting this property.</p>

<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
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>

<p>Making this value greater than</p>
<h2 id='author' class='heading'>Author</h2>

<p>Luis Padron</p>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<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>

</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
Expand All @@ -279,11 +322,15 @@ <h4>Declaration</h4>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The max value for the progress ring. ex: 23/(100)
Used to calculate amount of progress depending on self.value and self.maxValue</p>
<p>The maximum value for the progress ring. ex: 0 -&gt; (100)</p>
<h2 id='important' class='heading'>Important</h2>

<p>Default = 100</p>

<p>Must be a non-negative value, the absolute value is taken when setting this property.</p>

<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
is the inner ring will do an extra loop through the outer ring, this is not noticible however.</p>
<h2 id='author' class='heading'>Author</h2>

<p>Luis Padron</p>
Expand All @@ -293,7 +340,7 @@ <h2 id='author' class='heading'>Author</h2>
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<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>
<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>

</div>
</div>
Expand Down Expand Up @@ -689,9 +736,9 @@ <h4>Declaration</h4>
<li class="item">
<div>
<code>
<a name="/s:22UICircularProgressRing0abC4ViewC13outerCapStyleSo06CGLineF0Ov"></a>
<a name="/s:22UICircularProgressRing0abC4ViewC13outerCapStyleSC06CGLineF0Ov"></a>
<a name="//apple_ref/swift/Property/outerCapStyle" class="dashAnchor"></a>
<a class="token" href="#/s:22UICircularProgressRing0abC4ViewC13outerCapStyleSo06CGLineF0Ov">outerCapStyle</a>
<a class="token" href="#/s:22UICircularProgressRing0abC4ViewC13outerCapStyleSC06CGLineF0Ov">outerCapStyle</a>
</code>
</div>
<div class="height-container">
Expand Down Expand Up @@ -838,9 +885,9 @@ <h4>Declaration</h4>
<li class="item">
<div>
<code>
<a name="/s:22UICircularProgressRing0abC4ViewC13innerCapStyleSo06CGLineF0Ov"></a>
<a name="/s:22UICircularProgressRing0abC4ViewC13innerCapStyleSC06CGLineF0Ov"></a>
<a name="//apple_ref/swift/Property/innerCapStyle" class="dashAnchor"></a>
<a class="token" href="#/s:22UICircularProgressRing0abC4ViewC13innerCapStyleSo06CGLineF0Ov">innerCapStyle</a>
<a class="token" href="#/s:22UICircularProgressRing0abC4ViewC13innerCapStyleSC06CGLineF0Ov">innerCapStyle</a>
</code>
</div>
<div class="height-container">
Expand Down Expand Up @@ -1360,6 +1407,50 @@ <h4>Declaration</h4>

</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>newVal</em>
</code>
</td>
<td>
<div>
<p>The value to be set for the progress ring</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>animationDuration</em>
</code>
</td>
<td>
<div>
<p>The time interval duration for the animation</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>completion</em>
</code>
</td>
<td>
<div>
<p>The completion closure block that will be called when
animtion is finished (also called when animationDuration = 0), default is nil</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</li>
Expand All @@ -1368,8 +1459,8 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<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>
<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>
<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>
<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>
</section>
</article>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<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>
<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>
<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>
<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>
</section>
</article>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums/UICircularProgressRingGradientPosition.html
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<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>
<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>
<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>
<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>
</section>
</article>
</div>
Expand Down
Loading

0 comments on commit 4a20998

Please sign in to comment.