-
Notifications
You must be signed in to change notification settings - Fork 144
/
RelativeView.swift
100 lines (79 loc) · 3.95 KB
/
RelativeView.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
92
93
94
95
96
97
98
99
100
// Copyright (c) 2017 Luc Dion
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import UIKit
import PinLayout
class RelativeView: UIView {
private let centerView = UIView()
private let topLeftView = UIView()
private let topCenterView = UIView()
private let topRightView = UIView()
private let leftTopView = UIView()
private let leftCenterView = UIView()
private let leftBottomView = UIView()
private let bottomLeftView = UIView()
private let bottomCenterView = UIView()
private let bottomRightView = UIView()
private let rightTopView = UIView()
private let rightCenterView = UIView()
private let rightBottomView = UIView()
private let relativeView = UIView()
private let childRelativeView = UIView()
init() {
super.init(frame: .zero)
backgroundColor = .white
centerView.backgroundColor = .pinLayoutColor
addSubview(centerView)
addSquare(topLeftView, color: .lightGray)
addSquare(topCenterView, color: .gray)
addSquare(topRightView, color: .lightGray)
addSquare(leftTopView, color: .lightGray)
addSquare(leftCenterView, color: .gray)
addSquare(leftBottomView, color: .lightGray)
addSquare(bottomLeftView, color: .lightGray)
addSquare(bottomCenterView, color: .gray)
addSquare(bottomRightView, color: .lightGray)
addSquare(rightTopView, color: .lightGray)
addSquare(rightCenterView, color: .gray)
addSquare(rightBottomView, color: .lightGray)
}
private func addSquare(_ view: UIView, color: UIColor) {
view.backgroundColor = color
view.pin.size(40)
addSubview(view)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func layoutSubviews() {
super.layoutSubviews()
centerView.pin.center().size(150)
topLeftView.pin.above(of: centerView, aligned: .left).marginBottom(10)
topCenterView.pin.above(of: centerView, aligned: .center).marginBottom(10)
topRightView.pin.above(of: centerView, aligned: .right).marginBottom(10)
rightTopView.pin.after(of: centerView, aligned: .top).marginLeft(10)
rightCenterView.pin.after(of: centerView, aligned: .center).marginLeft(10)
rightBottomView.pin.after(of: centerView, aligned: .bottom).marginLeft(10)
bottomLeftView.pin.below(of: centerView, aligned: .left).marginTop(10)
bottomCenterView.pin.below(of: centerView, aligned: .center).marginTop(10)
bottomRightView.pin.below(of: centerView, aligned: .right).marginTop(10)
leftTopView.pin.before(of: centerView, aligned: .top).marginRight(10)
leftCenterView.pin.before(of: centerView, aligned: .center).marginRight(10)
leftBottomView.pin.before(of: centerView, aligned: .bottom).marginRight(10)
}
}