 @IBDesignable
 class CustomProgressView: UIView {
     
+    
     @IBInspectable var progress: CGFloat = 0 {
         didSet {
             if progress < 0.0 {

        reframeLayers(rect)
    }

    private func updateLayerProgress() {
        var fromStroke: CGFloat
        var toStroke: CGFloat
        var fromAngle: CGFloat
        var toAngle: CGFloat
        
        fromStroke = circlePathLayer.strokeEnd

        if progress > 1.0 {
            toStroke = 1.0
            circlePathLayer.strokeEnd = 1.0
        } else {
            toStroke = progress
            circlePathLayer.strokeEnd = progress
        }

        fromAngle = oldAngle

        let delta: CGFloat = CGFloat(M_PI * 2.0) * progress - oldAngle
        let rotate = CATransform3DRotate(endCapLayer.transform, delta, 0, 0, 1)
        toAngle = oldAngle + delta

        
        endCapLayer.transform = rotate

        endCapLayer.addAnimation(endCapAnimation(fromAngle, toAngle: toAngle), forKey: "transform.rotation.z")
        circlePathLayer.addAnimation(circleAnimation(fromStroke, toStroke: toStroke, fromAngle: fromAngle, toAngle: toAngle), forKey: "strokeEnd")
        
        oldAngle = toAngle
    }
        
    private func setupShapeLayers() {
        let frame = circleFrame()

        setupShapeLayer(startCapLayer, frame: frame)

        setupShapeLayer(circlePathLayer, frame: frame)
        circlePathLayer.lineWidth = lineWidth

        setupShapeLayer(endCapLayer, frame: frame)
        endCapLayer.shadowColor = UIColor.blackColor().CGColor
        endCapLayer.shadowRadius = lineWidth
        endCapLayer.shadowOpacity = 0.6
        endCapLayer.shadowOffset = CGSizeMake(lineWidth, 0)
    }


    private func setupShapeLayer(shapeLayer: CAShapeLayer, frame: CGRect) {
        shapeLayer.fillColor = UIColor.clearColor().CGColor
        shapeLayer.strokeColor = color?.CGColor

    
    @IBInspectable var color: UIColor? {
        didSet {
            arcLayer.strokeColor = color?.CGColor
            endLayer.fillColor = color?.CGColor
            startLayer.fillColor = color?.CGColor
        }
    }
    
    @IBInspectable var lineWidth: CGFloat = 1 {
        didSet {
            arcLayer.lineWidth = lineWidth
            endLayer.path = endCapPath().CGPath
            startLayer.path = endCapPath().CGPath
        }
    }
    
    @IBInspectable var shadowRadius: CGFloat = 10 {
        didSet {
            endLayer.shadowRadius = shadowRadius
        }
    }

    @IBInspectable var shadowOffset: CGSize = CGSizeZero {
        didSet {
            endLayer.shadowOffset = shadowOffset
        }
    }

    @IBInspectable var shadowOpacity: Float = 0.5 {
        didSet {
            endLayer.shadowOpacity = shadowOpacity
        }
    }

    @IBInspectable var shadowColor: UIColor? {
        didSet {
            endLayer.shadowColor = shadowColor?.CGColor
        }
    }
    
    @IBInspectable var rotationDuration: Float = 0.5
    
    
    
    
    private let arcLayer = CAShapeLayer()
    private let endLayer = CAShapeLayer()
    private let startLayer = CAShapeLayer()
    
    private var oldAngle: CGFloat = 0
    private var oldProgress: CGFloat = 0
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        // Make sure the initial value is 0
        arcLayer.strokeEnd = 0.0
        
        setupShapeLayers()
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        // Make sure the initial value is 0
        arcLayer.strokeEnd = 0.0
        
        setupShapeLayers()
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
