forked from SnapKit/SnapKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleLayoutViewController.swift
More file actions
97 lines (76 loc) · 2.59 KB
/
SimpleLayoutViewController.swift
File metadata and controls
97 lines (76 loc) · 2.59 KB
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
92
93
94
95
96
97
//
// SimpleLayoutViewController.swift
// SnapKit
//
// Created by Spiros Gerokostas on 01/03/16.
// Copyright © 2016 SnapKit Team. All rights reserved.
//
import UIKit
class SimpleLayoutViewController: UIViewController {
var didSetupConstraints = false
let blackView: UIView = {
let view = UIView()
view.backgroundColor = .black
return view
}()
let redView: UIView = {
let view = UIView()
view.backgroundColor = .red
return view
}()
let yellowView: UIView = {
let view = UIView()
view.backgroundColor = .yellow
return view
}()
let blueView: UIView = {
let view = UIView()
view.backgroundColor = .blue
return view
}()
let greenView: UIView = {
let view = UIView()
view.backgroundColor = .green
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
view.addSubview(blackView)
view.addSubview(redView)
view.addSubview(yellowView)
view.addSubview(blueView)
view.addSubview(greenView)
view.setNeedsUpdateConstraints()
}
override func updateViewConstraints() {
if (!didSetupConstraints) {
blackView.snp.makeConstraints { make in
make.center.equalTo(view)
make.size.equalTo(CGSize(width: 100, height: 100))
}
redView.snp.makeConstraints { make in
make.top.equalTo(blackView.snp.bottom).offset(20.0)
make.right.equalTo(blackView.snp.left).offset(-20.0)
make.size.equalTo(CGSize(width: 100, height: 100))
}
yellowView.snp.makeConstraints { make in
make.top.equalTo(blackView.snp.bottom).offset(20.0)
make.left.equalTo(blackView.snp.right).offset(20.0)
make.size.equalTo(CGSize(width: 100, height: 100))
}
blueView.snp.makeConstraints { make in
make.bottom.equalTo(blackView.snp.top).offset(-20.0)
make.left.equalTo(blackView.snp.right).offset(20.0)
make.size.equalTo(CGSize(width: 100, height: 100))
}
greenView.snp.makeConstraints { make in
make.bottom.equalTo(blackView.snp.top).offset(-20.0)
make.right.equalTo(blackView.snp.left).offset(-20.0)
make.size.equalTo(CGSize(width: 100, height: 100))
}
didSetupConstraints = true
}
super.updateViewConstraints()
}
}