         return animation;
     }
     
-    
     //MARK: - CAAnimation Delegate
-    
+
     
     override public func animationDidStart(anim: CAAnimation){
         animationDidStartClosure(on)

        shape.anchorPoint = CGPointMake(0.5, 0.5);
        shape.path = UIBezierPath(ovalInRect: CGRectMake(0, 0, radius * 2, radius * 2)).CGPath
    }


    override public func awakeFromNib() {
        let shapeColor: UIColor = onTintColor ?? UIColor.greenColor()
        
        layer.borderWidth = 0.5
        layer.borderColor = UIColor.whiteColor().CGColor;
        layer.cornerRadius = frame.size.height / 2;
        
        shape.fillColor = shapeColor.CGColor
        shape.masksToBounds = true
        
        superview?.layer.insertSublayer(shape, atIndex: 0)
        superview?.layer.masksToBounds = true
        
        showShapeIfNeed()
        
        addTarget(self, action: "switchChanged", forControlEvents: UIControlEvents.ValueChanged)
      
        super.awakeFromNib()
    }
  
    
    private func showShapeIfNeed() {
        shape.transform = on ? CATransform3DMakeScale(1.0, 1.0, 1.0) : CATransform3DMakeScale(0.0001, 0.0001, 0.0001)
    }


    internal func switchChanged() {
        if on == oldState {
            return;

    }
    
    
    // MARK: - Initialization

    
    public required init(view: UIView?) {
        super.init(frame: CGRectZero)
        self.commonInit(view)
    }
    
    
    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    
    override public func awakeFromNib() {
        self.commonInit(superview)
        super.awakeFromNib()
    }
    
    
    private func commonInit(parentView: UIView?) {
        let shapeColor: UIColor = onTintColor ?? UIColor.greenColor()
        
        layer.borderWidth = 0.5
        layer.borderColor = UIColor.whiteColor().CGColor;
        layer.cornerRadius = frame.size.height / 2;
        
        shape.fillColor = shapeColor.CGColor
        shape.masksToBounds = true
        
        parentView?.layer.insertSublayer(shape, atIndex: 0)
        parentView?.layer.masksToBounds = true
        
        showShapeIfNeed()
        
        addTarget(self, action: "switchChanged", forControlEvents: UIControlEvents.ValueChanged)
    }
    
    
    override public func layoutSubviews() {
        let x:CGFloat = max(frame.midX, superview!.frame.size.width - frame.midX);
        let y:CGFloat = max(frame.midY, superview!.frame.size.height - frame.midY);
