             view.translatesAutoresizingMaskIntoConstraints = false
             addSubview(view)
             
-            constraints.append(view.top(to: previous ?? self, previous?.bottomAnchor ?? topAnchor, offset: offset))
-            constraints.append(view.left(to: self))
-            constraints.append(view.right(to: self))
+            switch axis {
+            case .vertical:
+                constraints.append(view.top(to: previous ?? self, previous?.bottomAnchor ?? topAnchor, offset: offset))
+                constraints.append(view.left(to: self))
+                constraints.append(view.right(to: self))
+                
+                if let lastView = views.last, view == lastView {
+                    constraints.append(view.bottom(to: self))
+                }
+            case .horizontal:
+                constraints.append(view.top(to: self))
+                constraints.append(view.bottom(to: self))
+                constraints.append(view.left(to: previous ?? self, previous?.rightAnchor ?? leftAnchor, offset: offset))
+                
+                if let lastView = views.last, view == lastView {
+                    constraints.append(view.right(to: self))
+                }
+            }
             
             if let width = width {
                 constraints.append(view.width(width))

            previous = view
        }
        
        if let bottom = previous?.bottom(to: self) {
            constraints.append(bottom)
        }
        
        return constraints
    }
    
    fileprivate func stackLeftToRight(views: [UIView], width: CGFloat? = nil, height: CGFloat? = nil, spacing: CGFloat = 0) -> Constraints {
        
        var offset: CGFloat = 0
        var previous: UIView?
        var constraints: Constraints = []
        
        for view in views {
            view.translatesAutoresizingMaskIntoConstraints = false
            addSubview(view)
            
            constraints.append(view.top(to: self))
            constraints.append(view.bottom(to: self))
            constraints.append(view.left(to: previous ?? self, previous?.rightAnchor ?? leftAnchor, offset: offset))
            
            if let width = width {
                constraints.append(view.width(width))
            }
            
            if let height = height {
                constraints.append(view.height(height))
            }
            
            offset = spacing
            previous = view
        }
        
        if let right = previous?.right(to: self) {
            constraints.append(right)
        }
        
        return constraints
    }
}


import UIKit

public enum StackAxis {
    case horizontal
    case vertical
}

public extension UIView {
    
    @discardableResult
    public func stack(_ views: [UIView], axis: StackAxis = .vertical, width: CGFloat? = nil, height: CGFloat? = nil, spacing: CGFloat = 0) -> Constraints {
        
        var offset: CGFloat = 0
        var previous: UIView?
