     // MARK: - UIView
     
     override func layoutSubviews() {
+        updateBackgroundsIfNeeded()
         updateViewIfNeeded()
         super.layoutSubviews()
     }
-
+    
+    override func draw(_ rect: CGRect) {
+        super.draw(rect)
+        updateShadowIfNeeded()
+    }
+    
 }
+
+fileprivate extension Dictionary {
+    
+    mutating func setValueOrRemoveNil(_ valueOrNil: Value?, forKey key: Key) {
+        if let value = valueOrNil {
+            self[key] = value
+        } else {
+            self.removeValue(forKey: key)
+        }
+    }
+    
+}
+
+fileprivate extension UIView {
+    
+    func apply(shadow: NSShadow?) {
+        if let shadowColor = shadow?.shadowColor as? UIColor {
+            layer.shadowColor = shadowColor.cgColor
+        }
+        layer.shadowRadius = shadow?.shadowBlurRadius ?? 0.0
+        layer.shadowOffset = shadow?.shadowOffset ?? CGSize.zero
+        layer.shadowOpacity = shadow != nil ? 1.0 : 0.0
+        layer.masksToBounds = shadow == nil
+    }
+    
+}

        }
    }

    // MARK: - UpdateView
    
    private func setNeedsUpdateView() {


import UIKit

@IBDesignable class DrawingButton: UIButton {

    // MARK: - Variables

    private var iconDrawViewForStateDict = [NSNumber: DrawingView]()
    private var backgroundDrawViewForStateDict = [NSNumber: DrawingView]()
    private var shadowForStateDict = [NSNumber: NSShadow]()
    private var needsUpdateShadow = true
    private var backgroundSize = CGSize.zero

    @IBInspectable var iconName: String? {
        didSet {
