A vertical stackview which takes subviews with different widths and adds them to it's rows with paddings, spacings etc.
pod 'EEStackLayout', '~> 0.1'
pod install
.package(url: "https://github.com/efekanegeli/EEStackLayout.git", from: "0.1.11")
1. Download .zip file
2. Just drag and drop EEStackLayout.swift to your project
// Subviews that will be added to stack layout
varviewArray=[UIView]()
// Choose the orientation of EEStackLayout -> vertical / horizontal [Just for demo purposes, change it if you want to see how horizontal EEStackLayout works]
lettargetOrientationOfStackLayout=NSLayoutConstraint.Axis.vertical
letstackLayout:EEStackLayoutif targetOrientationOfStackLayout ==.vertical {
// Vertical EEStackLayout
// Views with same height for the vertical layout
for_in1...25{letview1=UIView(frame:CGRect(x:0, y:0, width:20, height:42))
view1.backgroundColor =.green
letview2=UIView(frame:CGRect(x:0, y:0, width:30, height:42))
view2.backgroundColor =.blue
letview3=UIView(frame:CGRect(x:0, y:0, width:40, height:42))
view3.backgroundColor =.yellow
letview4=UIView(frame:CGRect(x:0, y:0, width:50, height:42))
view4.backgroundColor =.black
viewArray.append(view1)
viewArray.append(view2)
viewArray.append(view3)
viewArray.append(view4)}
// Vertical EEStackLayout setup
stackLayout =EEStackLayout(frame:CGRect(x:0, y:50, width:300, height:0),
rowHeight:20,
minimumInteritemSpacing:15,
minimumItemSpacing:10,
insets:UIEdgeInsets(top:15, left:15, bottom:15, right:15),
subviews: viewArray)}else{
// Horizontal EEStackLayout
// Views with same width for the horizontal layout
for_in1...25{letview1=UIView(frame:CGRect(x:0, y:0, width:30, height:15))
view1.backgroundColor =.green
letview2=UIView(frame:CGRect(x:0, y:0, width:30, height:25))
view2.backgroundColor =.blue
letview3=UIView(frame:CGRect(x:0, y:0, width:30, height:35))
view3.backgroundColor =.yellow
letview4=UIView(frame:CGRect(x:0, y:0, width:30, height:45))
view4.backgroundColor =.black
viewArray.append(view1)
viewArray.append(view2)
viewArray.append(view3)
viewArray.append(view4)}
// Horizontal EEStackLayout setup
stackLayout =EEStackLayout(frame:CGRect(x:0, y:50, width:0, height:400),
columnWidth:20,
minimumInteritemSpacing:15,
minimumItemSpacing:10,
insets:UIEdgeInsets(top:15, left:15, bottom:15, right:15),
subviews: viewArray)}self.view.addSubview(stackLayout)minimumItemSpacing -> Spacing between rows(vertical layout) or colums(horizontal layout)
rowHeight -> Row height of the main vertical stack view
maximumRowCount -> Maximum row count of the vertical stack view, ignores the rest of the subviews if the actual row count exceeds the limit
columnWidth -> Column width of the main horizontal stack view
maximumColumnCount -> Maximum column count of the horizontal stack view, ignores the rest of the subviews if the actual column count exceeds the limit
minimumInteritemSpacing -> Spacing between items in a row/column
insets -> Layout margins of main vertical stack view
subviews -> View array of elements to be added to the main stack view
MIT License, Copyright (c) 2018 Efekan Egeli, @efekanegeli
