      */
     fileprivate func updateSpacingConstraints(){
         if !isExpanded {
-            for constraint in itemSpacingConstraints {
-                constraint.constant = halfImageWidth + imageSpacing
+            for constraint in rightItemSpacingConstraints { constraint.constant = halfImageWidth + imageSpacing }
+            for constraint in leftItemSpacingConstraints { constraint.constant = -(halfImageWidth + imageSpacing) }
+
+            if let middleRightConstraint = self.rightMiddleItemSpacingConstraint, let middleLeftConstraint = self.leftMiddleItemSpacingConstraint {
+                middleRightConstraint.constant = halfImageWidth + imageSpacing
+                middleLeftConstraint.constant = -(halfImageWidth + imageSpacing)
             }
-        } else {
-            for constraint in itemSpacingConstraints {
-                constraint.constant = 1
+        }
+        else {
+            for constraint in rightItemSpacingConstraints { constraint.constant = 1 }
+            for constraint in leftItemSpacingConstraints { constraint.constant = 1 }
+
+            if let middleRightConstraint = self.rightMiddleItemSpacingConstraint, let middleLeftConstraint = self.leftMiddleItemSpacingConstraint {
+                middleRightConstraint.constant = (halfImageWidth + imageSpacing)/2.0
+                middleLeftConstraint.constant = -((halfImageWidth + imageSpacing)/2.0)
             }
         }
     }

    fileprivate func setupInitialLayout() {
        
        var layoutConstraints:[NSLayoutConstraint] = []
//        let middleItem: UIImageView? = icons.count % 2 != 0 ? icons[((icons.count - 1)/2)] : nil
        
        // If it's an odd # of icons (there is a clear middle item)
        if let middleIndex = icons.count % 2 != 0 ? (icons.count - 1)/2 : nil {
            
            for index in middleIndex ..< icons.count - 1 {
                
                let currentView = icons[index]
                
                // Center vertically to containing scrollView
                layoutConstraints.append(NSLayoutConstraint(item: currentView, attribute: NSLayoutAttribute.centerY, relatedBy: .equal, toItem: scrollView, attribute: .centerY, multiplier: 1, constant: 0))
                
                // Set width & height to 80% of the scrollView's height
                layoutConstraints.append(NSLayoutConstraint(item: currentView, attribute: .width, relatedBy: .equal, toItem: scrollView, attribute: .height, multiplier: 0.8, constant: 0))
                layoutConstraints.append(NSLayoutConstraint(item: currentView, attribute: .height, relatedBy: .equal, toItem: scrollView, attribute: .height, multiplier: 0.8, constant: 0))
                
                // If this is the middle item
                if (index == middleIndex) {
                    let centerItemXConstraint = NSLayoutConstraint(item: currentView,
                            attribute: NSLayoutAttribute.centerX,
                            relatedBy: .equal,
                            toItem: scrollView,
                            attribute: NSLayoutAttribute.centerX,
                            multiplier: 1,
                            constant: 0)
                    
                    layoutConstraints.append(centerItemXConstraint)
                }
                    
                // Proceed to do layout for next left + right items
                else {
                    let distanceFromCenter = index - middleIndex
                    let leftView = icons[middleIndex - distanceFromCenter]
                    
                    let previousLeftView = icons[(middleIndex - distanceFromCenter) + 1]
                    let previousRightView = icons[index-1]
                    
//                    let leftViewRightMarginConstraint = NSLayoutConstraint(item: leftView,
//                            attribute: .right,
//                            relatedBy: .equal,
//                            toItem: previousLeftView,
//                            attribute: .centerX,
//                            multiplier: 1,
//                            constant: 1)
//                    
//                    let rightViewLeftMarginConstraint = NSLayoutConstraint(item: currentView,
//                            attribute: .left,
//                            relatedBy: .equal,
//                            toItem: previousRightView,
//                            attribute: .centerX,
//                            multiplier: 1,
//                            constant: 1)
                    
//                    self.itemSpacingConstraints.append(leftViewRightMarginConstraint)
//                    self.itemSpacingConstraints.append(rightViewLeftMarginConstraint)
                    
                    let leftViewXConstraint = NSLayoutConstraint(item: leftView,
                            attribute: .right,
                            relatedBy: .equal,
                            toItem: previousLeftView,
                            attribute: .centerX,
                            multiplier: 1,
                            constant: 1)
                    
                    let rightViewXConstraint = NSLayoutConstraint(item: currentView,
                            attribute: .left,
                            relatedBy: .equal,
                            toItem: previousRightView,
                            attribute: .centerX,
                            multiplier: 1,
                            constant: 1)
                    
                    self.itemSpacingConstraints.append(leftViewXConstraint)
                    self.itemSpacingConstraints.append(rightViewXConstraint)
                }
            }
            
            layoutConstraints.append(contentsOf: self.itemSpacingConstraints)
            scrollView.addConstraints(layoutConstraints)
            
            addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[container]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["container":scrollView]))
            addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[container]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["container":scrollView]))
            isSetupFinished = true
        }
//        else {
//            
//        }
    
        
//        for i in 0 ..< icons.count  {
//            let currentView = icons[i]
//            
//            // UIImage's constraint to vertically centered to containing scrollview
//            layoutConstraints.append(NSLayoutConstraint(item: currentView, attribute: NSLayoutAttribute.centerY, relatedBy: .equal, toItem: scrollView, attribute: .centerY, multiplier: 1, constant: 0))
//            
//            // UIImage's constraint for setting the width/height to be 80% of containing scrollview's height
//            layoutConstraints.append(NSLayoutConstraint(item: currentView, attribute: .width, relatedBy: .equal, toItem: scrollView, attribute: .height, multiplier: 0.8, constant: 0))
//            layoutConstraints.append(NSLayoutConstraint(item: currentView, attribute: .height, relatedBy: .equal, toItem: scrollView, attribute: .height, multiplier: 0.8, constant: 0))
//            
//            // x axis constraints
//            
//            if i == 0 {
//                let marginLeftConstraint = NSLayoutConstraint(item: currentView,
//                    attribute: NSLayoutAttribute.left,
//                    relatedBy: .equal,
//                    toItem: scrollView,
//                    attribute: NSLayoutAttribute.left,
//                    multiplier: 1, constant: 0)
//                
//                layoutConstraints.append(marginLeftConstraint)
//                
//            } else {
//                let previousView = icons[i-1]
//                itemSpacingConstraints.append(NSLayoutConstraint(item: currentView,
//                    attribute: .left,
//                    relatedBy: .equal ,
//                    toItem: previousView,
//                    attribute: .centerX,
//                    multiplier: 1,
//                    constant: 1))
//            }
//        }
//        
//        layoutConstraints.append(contentsOf: itemSpacingConstraints)
//        scrollView.addConstraints(layoutConstraints)
//        
//        addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[container]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["container":scrollView]))
//        
//        addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[container]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["container":scrollView]))
//        
//        isSetupFinished = true
        
    }
    
    /**

    fileprivate var scrollView:UIScrollView
    fileprivate var isSetupFinished : Bool = false
    fileprivate var isExpanded : Bool = false
    fileprivate var rightMiddleItemSpacingConstraint: NSLayoutConstraint!
    fileprivate var leftMiddleItemSpacingConstraint: NSLayoutConstraint!
    fileprivate var rightItemSpacingConstraints : [NSLayoutConstraint] = []
    fileprivate var leftItemSpacingConstraints : [NSLayoutConstraint] = []
    
    open var imageSpacing:CGFloat = 4.0
    open var onExpanded: (()->())?
