A structured vertical/horizontal stack layout

Overview

EEStackLayout

A vertical stackview which takes subviews with different widths and adds them to it's rows with paddings, spacings etc.

Twitter: @efekanegeli CocoaPods

Screenshot

Installation

Cocoapods

pod 'EEStackLayout', '~> 0.1'
pod install

Swift Package Manager

.package(url: "https://github.com/efekanegeli/EEStackLayout.git", from: "0.1.11")

Manual

1. Download .zip file
2. Just drag and drop EEStackLayout.swift to your project

Example Usage

// Subviews that will be added to stack layout
var viewArray = [UIView]()

// Choose the orientation of EEStackLayout -> vertical / horizontal [Just for demo purposes, change it if you want to see how horizontal EEStackLayout works]
let targetOrientationOfStackLayout = NSLayoutConstraint.Axis.vertical

let stackLayout: EEStackLayout

if targetOrientationOfStackLayout == .vertical {
    // Vertical EEStackLayout

    // Views with same height for the vertical layout
    for _ in 1...25 {
        let view1 = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 42))
        view1.backgroundColor = .green
        let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 42))
        view2.backgroundColor = .blue
        let view3 = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 42))
        view3.backgroundColor = .yellow
        let view4 = 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 _ in 1...25 {
        let view1 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 15))
        view1.backgroundColor = .green
        let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 25))
        view2.backgroundColor = .blue
        let view3 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 35))
        view3.backgroundColor = .yellow
        let view4 = 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)

Init Properties

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

License

MIT License, Copyright (c) 2018 Efekan Egeli, @efekanegeli

You might also like...
LayoutKit is a fast view layout library for iOS, macOS, and tvOS.
LayoutKit is a fast view layout library for iOS, macOS, and tvOS.

๐Ÿšจ UNMAINTAINED ๐Ÿšจ This project is no longer used by LinkedIn and is currently unmaintained. LayoutKit is a fast view layout library for iOS, macOS, a

A powerful Swift programmatic UI layout framework.
A powerful Swift programmatic UI layout framework.

Build dynamic and beautiful user interfaces like a boss, with Swift. Neon is built around how user interfaces are naturally and intuitively designed.

Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]
Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]

Extremely Fast views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainabl

A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:
A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:

Cartography ๐Ÿ“ฑ ๐Ÿ“ Using Cartography, you can set up your Auto Layout constraints in declarative code and without any stringly typing! In short, it all

An easy way to create and layout UI components for iOS (Swift version).
An easy way to create and layout UI components for iOS (Swift version).

Introduction Cupcake is a framework that allow you to easily create and layout UI components for iOS 8.0+. It use chaining syntax and provides some fr

Auto Layout made easy
Auto Layout made easy

EasyPeasy is a Swift framework that lets you create Auto Layout constraints programmatically without headaches and never ending boilerplate code. Besi

Lightweight Swift framework for Apple's Auto-Layout
Lightweight Swift framework for Apple's Auto-Layout

I am glad to share with you a lightweight Swift framework for Apple's Auto-Layout. It helps you write readable and compact UI code using simple API. A

An Impressive Auto Layout DSL for  iOS, tvOS & OSX. & It is written in pure swift.
An Impressive Auto Layout DSL for iOS, tvOS & OSX. & It is written in pure swift.

KVConstraintKit KVConstraintKit is a DSL to make easy & impressive Auto Layout constraints on iOS, tvOS & OSX with Swift Installation Using CocoaPods

A compact but full-featured Auto Layout DSL for Swift
A compact but full-featured Auto Layout DSL for Swift

Mortar allows you to create Auto Layout constraints using concise, simple code statements. Use this: view1.m_right |=| view2.m_left - 12.0 Instead of:

Releases(0.1.11)
Owner
null
๐Ÿ— MondrianLayout - describing structured layout for AutoLayout

?? A DSL based layout builder for AutoLayout

Muukii 155 Dec 10, 2022
A flexible collection view with proper horizontal layout flow

FlexCollection A very simple flexible collection view using SwiftUI that automat

null 1 Dec 29, 2021
Multiple UI adaptable vertical segments slider

SSVerticalSegmentsSlider It's a vertical segment slider developed in SwiftUI. It offers many properties to create different UI that fit your needs. We

smartSense Solutions 18 Oct 16, 2022
LazyHList: Horizontal list with lazy loading with dequeueing

LazyHList LazyVStack and LazyHStack does load content lazly however they do not

Sezer Tunca 0 Dec 17, 2021
Auto Layout (and manual layout) in one line.

Auto Layout (and manual layout) in one line. Quick Look view.bb.centerX().below(view2).size(100) Itโ€™s equivalent to iOS 9 API: view.centerXAnchor.cons

Javier Zhang 74 Oct 19, 2022
Auto Layout made easy with the Custom Layout.

Auto Layout made easy with the Custom Layout. Getting started CocoaPods CocoaPods is a dependency manager for Cocoa projects. You can install it with

Malith Nadeeshan 1 Jan 16, 2022
AppStoreClone - Understanding the complex layout of app store using UICompositional layout in swift

AppStoreClone Understanding the complex layout of app store using UICompositiona

Dheeraj Kumar Sharma 8 Dec 28, 2022
A custom layout built on top of SwiftUI's Layout API that lays elements out in multiple lines. Similar to flex-wrap in CSS, CollectionViewFlowLayout.

WrapLayout A custom layout built on top of SwiftUI's Layout API that lays elements out in multiple lines. Similar to flex-wrap in CSS, CollectionViewF

Hiroshi Kimura 6 Sep 27, 2022
SwiftUI stack views with paged scrolling behaviour.

SwiftUI PageView SwiftUI stack views with paged scrolling behaviour. HPageView A view that arranges its children in a horizontal line, and provides pa

Ciaran O'Brien 41 Dec 21, 2022
BrickKit is a delightful layout library for iOS and tvOS. It is written entirely in Swift!

BrickKit is a delightful layout library for iOS and tvOS. It is written entirely in Swift! Deprecated BrickKit is being phased out at Wayfair, and the

Wayfair Tech โ€“ Archive 608 Sep 15, 2022