/
ViewController.swift
92 lines (74 loc) · 3.73 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// ViewController.swift
// EEStackLayout
//
// Created by Efekan Egeli on 5.06.2018.
// Copyright © 2018 Efekan Egeli. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = .orange
// 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)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}