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

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

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

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

    @IBInspectable var shadowColor: UIColor? {
        didSet {
            endCapLayer.shadowColor = shadowColor?.CGColor
        }
    }
    
    @IBInspectable var rotationDuration: Float = 0.5 {
        didSet {
//            endCapLayer.rotationDuration = rotationDuration
//            circlePathLayer.rotationDuration = rotationDuration
        }
    }
        
    private let circlePathLayer = CAShapeLayer()
    private let endCapLayer = CAShapeLayer()
    private let startCapLayer = CAShapeLayer()
    
    private var oldAngle: CGFloat = 0
    private var oldProgress: CGFloat = 0
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        circlePathLayer.strokeEnd = 0.0
        setupShapeLayers()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        circlePathLayer.strokeEnd = 0.0
        setupShapeLayers()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()

        layer.addSublayer(shapeLayer)
    }

    
    /// A utility called to update the CAShapeLayers when the view is laying
    /// out it's subviews.  Each layers frame property is updated and then
    /// a new CGPath is loaded into the layer.
    ///
    /// parameter frame: A CGRect that is the new frame to use for the views
    private func reframeLayers(frame: CGRect) {
        reframeLayer(startLayer, frame: frame)
        startLayer.path = endCapPath().CGPath

        reframeLayer(arcLayer, frame: frame)
        arcLayer.path = circlePath().CGPath

        reframeLayer(endLayer, frame: frame)
        endLayer.path = endCapPath().CGPath
    }

    
    /// A utility method used to properly update the frame for CAShapeLayer.
    private func reframeLayer(layer: CAShapeLayer, frame: CGRect) {
        layer.bounds = CGRect(origin: CGPointZero, size: frame.size)
        layer.position = CGPoint(x: CGRectGetMidX(bounds), y: CGRectGetMidY(bounds))
    }

    
    /// A utility method that returns the frame to use for the shape layers that
    /// do all the work.  The frame is square with a width/height equal to
    /// one half the smallest dimension.
    ///
    /// - returns: A CGRect to use as the frame for a shape layer
    private func circleFrame() -> CGRect {
        let radius = min(bounds.width / 2, bounds.height / 2)
        let frame = CGRect(origin: CGPointMake(bounds.width / 2, bounds.height / 2), size: CGSizeZero)

        return CGRectInset(frame, -radius, -radius)
    }

    
    /// A utility method that returns the radius to use for the circle.  It
    /// assumes that the circle is being drawn with a stroke (no fill).  The
    /// circle is assumed to fill the entire views rect in the smallest
    /// direction.
    ///
    /// - returns: The radius to use.
    private func circleRadius() -> CGFloat {
        let rect = circleFrame()

        return min(rect.width, rect.height) / 2.0 - lineWidth
    }

    
    /// A utility method that returns the center of the circle.  This assumes
    /// that the view is square.
    ///
    /// - resturns: A CGPoint to use as the center point of the circle
    private func circleCenter() -> CGPoint {
        let radius = circleRadius() + lineWidth
        return CGPointMake(radius, radius)
    }


    /// A method for generating a UIBezierPath for the arc layer
    ///
    /// - returns: A UIBezierPath that is a arc that uses the current
    /// radius, and lineWidth.
    private func circlePath() -> UIBezierPath {
        let topAngle: CGFloat = CGFloat(-M_PI_2)
        let endAngle: CGFloat = CGFloat(2 * M_PI - M_PI_2)
