         }
     }
 
-    required init?(coder aDecoder: NSCoder) {
-        super.init(coder: aDecoder)
-    }
-    override init(frame: CGRect) {
-        super.init(frame: frame)
-        self.privateInit()
-        self.registerForNotifications()
-    }
-    override func awakeFromNib() {
-        super.awakeFromNib()
-        self.privateInit()
-        self.registerForNotifications()
-    }
-    override func prepareForInterfaceBuilder() {
-        self.privateInit()
-    }
-    deinit {
-        self.unregisterFromNotifications()
-    }
-
-    private func privateInit() {
-        self.setTitleColor(self.tintColor, forState: UIControlState.Normal)
-        self.setTitleColor(self.shapeBackgroundColor, forState: UIControlState.Highlighted)
-        self.layer.insertSublayer(self.shapeLayer, atIndex: 0)
-        self.layer.insertSublayer(self.crossLayer, atIndex: 1)
-        self.layer.insertSublayer(self.progressLayer, atIndex: 2)
-        self.updateToDefaultStateAnimated(false)
-    }
-
-    override func layoutSubviews() {
-        super.layoutSubviews()
-        self.shapeLayer.frame = self.layer.bounds
-        self.crossLayer.frame = self.layer.bounds
-        self.progressLayer.frame = self.layer.bounds
-    }
-    
+// MARK : Methods used to update states
+    
+    private var shapeLayer = CAShapeLayer()
+    private lazy var crossLayer: CAShapeLayer = {
+        let crossLayer = CAShapeLayer()
+        crossLayer.path = self.crossPath().CGPath
+        crossLayer.strokeColor = self.circleBorderColor.CGColor
+        return crossLayer
+        }()
+    private lazy var progressLayer: CAShapeLayer = {
+        let progressLayer = CAShapeLayer()
+        progressLayer.strokeColor = self.circleBorderColor.CGColor
+        progressLayer.fillColor = UIColor.clearColor().CGColor
+        return progressLayer
+        }()
+    private lazy var shapeBackgroundColor: UIColor = {
+        return self.backgroundColor ?? self.circleBackgroundColor
+        }()
+
     private func updateToDefaultStateAnimated(animated:Bool) {
         self.shapeLayer.strokeColor = self.borderColor.CGColor;
         self.shapeLayer.fillColor = self.shapeBackgroundColor.CGColor


import UIKit

/**
    ABProgressButton provides functionality for creating custom animation of UIButton during processing some task.
    Should be created in IB as custom class UIButton to prevent title of the button appearing.
*/
@IBDesignable @objc class ABProgressButton: UIButton {
    
    @IBInspectable var cornerRadius: CGFloat = 5.0
    @IBInspectable var borderWidth: CGFloat = 3.0
    @IBInspectable lazy var borderColor: UIColor = {
        return self.tintColor
    }()
    @IBInspectable lazy var circleBorderColor: UIColor = {
        return self.tintColor
    }()
    @IBInspectable var circleBorderWidth: CGFloat = 3.0
    @IBInspectable var circleRadius: CGFloat = 20.0
    @IBInspectable var circleCutAngle: CGFloat = 45.0
    @IBInspectable var circleBackgroundColor: UIColor = UIColor.whiteColor()
    private lazy var shapeBackgroundColor: UIColor = {
        return self.backgroundColor ?? self.circleBackgroundColor
    }()

    enum State {
        case Default, Progressing
    }
    var progressState: State = .Default {
        didSet {
            if(progressState == .Default) { self.updateToDefaultStateAnimated(true)}

        layer.addAnimation(animation, forKey: "rotation animation")
        UIView.animateWithDuration(textAppearingAnimationTime, animations: { () -> Void in
            self.titleLabel?.alpha = 0.0
            self.hideContentImage()
        })
    }
    
// MARK : Pathes creation for different states
    
    private func defaultStatePath() ->  UIBezierPath {
        let bordersPath = UIBezierPath(roundedRect:self.bounds, cornerRadius:self.cornerRadius)
