KDCircularProgress icon indicating copy to clipboard operation
KDCircularProgress copied to clipboard

Progress color changes to white at angle = 360

Open TarekSalama opened this issue 7 years ago • 0 comments

I am using KDCircularProgress as a counter so whenever the user taps on a button, the counter would increase by 1 and the progress gradient would increase until it hits 360. However I noticed some counter numbers such as 7 (and any number divisible by 7), 33, and 100 cause its color to be white when it reaches 360, instead of the full gradient color.

Here's a simplified code of the UIViewController which I tried in a separate project. The StoryBoard has a UIView of type KDCircularProgress and a button.

import UIKit
import AudioToolbox

class ViewController: UIViewController {
    @IBOutlet weak var countProgressCircle: KDCircularProgress!
    @IBOutlet weak var counterButton: UIButton!
    
    var currentCount = 0.0
    var testCount = 7.0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        countProgressCircle.startAngle = -90
        countProgressCircle.clockwise = false
        countProgressCircle.angle = 0
        countProgressCircle.trackColor = UIColor.progressCircleTrackColor
        countProgressCircle.progressColors = [UIColor.progressCircleGradient1,
                                              UIColor.progressCircleGradient2,
                                              UIColor.progressCircleGradient3,
                                              UIColor.progressCircleGradient4,
                                              UIColor.progressCircleGradient5,
                                              UIColor.progressCircleGradient6]
    }
    
    @IBAction func incrementCount(_ sender: Any) {
        if currentCount != testCount {
            let countSegment = 360.0 / Double(testCount)
            let currentAngle = countProgressCircle.angle
            let newAngle = currentAngle + countSegment
            
            guard currentCount != testCount else { return }
            
            currentCount += 1
            countProgressCircle.animate(toAngle: newAngle, duration: 0.3) { (complete) in
                self.counterButton.isEnabled = true
            }
            
            if currentCount == testCount {
                AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
            }
        } else {
            AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
        }
    }
    
}

extension UIColor {
    static let progressCircleGradient1 =  #colorLiteral(red: 0, green: 0.5254901961, blue: 0.6078431373, alpha: 1)
    static let progressCircleGradient2 =  #colorLiteral(red: 0.2549019608, green: 0.831372549, blue: 0.8156862745, alpha: 1)
    static let progressCircleGradient3 =  #colorLiteral(red: 0.3607843137, green: 0.2745098039, blue: 0.5254901961, alpha: 1)
    static let progressCircleGradient4 =  #colorLiteral(red: 0.4078431373, green: 0.3058823529, blue: 0.5921568627, alpha: 1)
    static let progressCircleGradient5 =  #colorLiteral(red: 1, green: 0.4509803922, blue: 0.4509803922, alpha: 1)
    static let progressCircleGradient6 =  #colorLiteral(red: 1, green: 0.6156862745, blue: 0.231372549, alpha: 1)
    static let progressCircleTrackColor = #colorLiteral(red: 0.9215686275, green: 0.9215686275, blue: 0.9215686275, alpha: 1)
}

TarekSalama avatar Jul 04 '18 15:07 TarekSalama