-
Notifications
You must be signed in to change notification settings - Fork 12
/
ApplyViewConstraint.swift
215 lines (182 loc) · 9.81 KB
/
ApplyViewConstraint.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//
// ApplyViewConstraint.swift
// https://github.com/keshavvishwkarma/KVConstraintKit.git
//
// Distributed under the MIT License.
//
// Copyright © 2016-2017 Keshav Vishwkarma <[email protected]>. All rights reserved.
//
// 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.
//
//
#if os(iOS) || os(tvOS)
import UIKit
#else
import AppKit
#endif
// MARK: - TO APPLY PREPARED SELF CONSTRAINTS -
extension View
{
// All of the below methods of this extension are used to Apply\Add constraint in receiver view (self ).
/// Sets the aspect ratio of a view.
@available(*, deprecated: 1.2, message: "Use 'applyAspectRatio' instead")
@discardableResult public final func applyAspectRatioConstraint() -> View {
return applyAspectRatio()
}
/// Sets the width of a view.
/// - Parameter width: A CGFloat value.
@available(*, deprecated: 1.2, message: "Use 'applyWidth' instead")
@discardableResult public final func applyWidthConstraint(_ width: CGFloat) -> View {
return applyWidth(width)
}
/// Sets the height of a view.
/// - Parameter height: A CGFloat value.
@available(*, deprecated: 1.2, message: "Use 'applyHeight' instead")
@discardableResult public final func applyHeightConstraint(_ height: CGFloat) -> View {
return applyHeight(height)
}
/// Sets the at least height of a view.
/// - Parameter height: A CGFloat value.
@available(*, deprecated: 1.2, message: "Use 'applyAtLeastHeight' instead")
@discardableResult public final func applyAtLeastHeightConstraint(_ height: CGFloat) -> View {
return applyAtLeastHeight(height)
}
/// Sets the at most height of a view.
/// - Parameter height: A CGFloat value.
@available(*, deprecated: 1.2, message: "Use 'applyAtMostHeight' instead")
@discardableResult public final func applyAtMostHeightConstraint(_ height: CGFloat) -> View {
return applyAtMostHeight(height)
}
/// Sets the at least width of a view.
/// - Parameter width: A CGFloat value.
@available(*, deprecated: 1.2, message: "Use 'applyAtLeastWidth' instead")
@discardableResult public final func applyAtLeastWidthConstraint(_ width: CGFloat) -> View {
return applyAtLeastWidth(width)
}
/// Sets the at most width of a view.
/// - Parameter width: A CGFloat value.
@available(*, deprecated: 1.2, message: "Use 'applyAtMostWidth' instead")
@discardableResult public final func applyAtMostWidthConstraint(_ width: CGFloat) -> View {
return applyAtMostWidth(width)
}
}
// MARK : - TO APPLIED PREPARED CONSTRAINTS
extension View
{
// All the below methods of this category are used to applied\add constraints in supreview of receiver view (self)
/// A receiver view is aligned from the left with padding.
/// - Parameter padding: A CGFloat value to the left side padding.
@available(*, deprecated: 1.2, message: "Use 'applyLeft' instead")
@discardableResult public final func applyLeftPinConstraintToSuperview(_ padding: CGFloat) -> View {
return applyLeft(padding)
}
/// A receiver view is aligned from the right with padding.
/// - Parameter padding: A CGFloat value to the right side padding.
@available(*, deprecated: 1.2, message: "Use 'applyRight' instead")
@discardableResult public final func applyRightPinConstraintToSuperview(_ padding: CGFloat) -> View {
return applyRight(padding)
}
/// A receiver view is aligned from the top with padding.
/// - Parameter padding: A CGFloat value to the top side padding.
@available(*, deprecated: 1.2, message: "Use 'applyTop' instead")
@discardableResult public final func applyTopPinConstraintToSuperview(_ padding: CGFloat) -> View {
return applyTop(padding)
}
/// A receiver view is aligned from the bottom with padding.
/// - Parameter padding: A CGFloat value to the bottom side padding.
@available(*, deprecated: 1.2, message: "Use 'applyBottom' instead")
@discardableResult public final func applyBottomPinConstraintToSuperview(_ padding: CGFloat) -> View {
return applyBottom(padding)
}
/// A receiver view is aligned from the left with padding.
/// - Parameter padding: A CGFloat value to the left side padding.
@available(*, deprecated: 1.2, message: "Use 'applyLeading' instead")
@discardableResult public final func applyLeadingPinConstraintToSuperview(_ padding: CGFloat) -> View {
return applyLeading(padding)
}
/// A receiver view is aligned from the right with padding.
/// - Parameter padding: A CGFloat value to the right side padding.
@available(*, deprecated: 1.2, message: "Use 'applyTrailing' instead")
@discardableResult public final func applyTrailingPinConstraintToSuperview(_ padding: CGFloat) -> View {
return applyTrailing(padding)
}
/// To horizontally Center a receiver view in it's superview with an optional offset value.
/// - Parameter offsetX: A CGFloat value for the offset along the x axis.
@available(*, deprecated: 1.2, message: "Use 'applyCenterX' instead")
@discardableResult public final func applyCenterXPinConstraintToSuperview(_ offsetX: CGFloat) -> View {
return applyCenterX(offsetX)
}
/// To vertically Center a receiver view in it's superview with an optional offset value.
/// - Parameter offsetY: A CGFloat value for the offset along the y axis.
@available(*, deprecated: 1.2, message: "Use 'applyCenterY' instead")
@discardableResult public final func applyCenterYPinConstraintToSuperview(_ offsetY: CGFloat) -> View {
return applyCenterY(offsetY)
}
}
// MARK: - TO APPLY PREPARED CONSTRAINTS FOR CENTERING VIEW
extension View
{
/// Centers the view horizontally in its `superview` with an optional offset.
/// - Parameter offsetX: A CGFloat value for the offset along the x axis.
/// - Returns: Itself, enabling chaining.
@available(*, deprecated: 1.2, message: "Use 'applyCenterX' instead")
public final func applyConstraintToCenterHorizontallyInSuperview(_ offsetX: CGFloat = 0) -> View {
return applyCenterX(offsetX)
}
/// Centers the view vertically in its superview with an optional offset.
/// - Parameter offsetY: A CGFloat value for the offset along the y axis
/// - Returns: Itself, enabling chaining.
@available(*, deprecated: 1.2, message: "Use 'applyCenterY' instead")
public final func applyConstraintToCenterVerticallyInSuperview(_ offsetY: CGFloat = 0) -> View {
return applyCenterY(offsetY)
}
/// Centers the view horizontally & vertically in its superview with an optional offset.
/// - Parameter offset: A CGFloat value for the offset along the x & y axis.
/// - Returns: Itself, enabling chaining.
@available(*, deprecated: 1.2, message: "Use 'applyCenter' instead")
public final func applyConstraintToCenterInSuperview(_ offset:CGPoint = CGPoint.zero) -> View {
return applyCenter()
}
}
extension View
{
/// To apply\add same leading, trailing, Top and Bottom pin constraints to superview with same optional padding.
/// - Parameter padding: A CGFloat value to the all side (left, right, top & bottm) padding between the receiver view & its superview.
@available(*, deprecated: 1.2, message: "Use 'fitToSuperview' instead")
@discardableResult public final func applyConstraintFitToSuperview(_ padding: CGFloat = 0) -> View {
return fitToSuperview(padding)
}
/// To apply\add same leading and trailing pin constraints to superview with same optional padding.
/// - Parameter padding: A CGFloat value to the left & right side padding between the receiver view & its superview.
@available(*, deprecated: 1.2, message: "Use 'fitHorizontallyToSuperview' instead")
@discardableResult public final func applyConstraintFitHorizontallyToSuperview(_ padding: CGFloat = 0) -> View {
return fitVerticallyToSuperview(padding)
}
/// To apply\add same top and bottom pin constraints to superview with same optional padding.
/// - Parameter padding: A CGFloat value to the top & bottom side padding between the receiver view & its superview.
@available(*, deprecated: 1.2, message: "Use 'fitVerticallyToSuperview' instead")
@discardableResult public final func applyConstraintFitVerticallyToSuperview(_ padding: CGFloat = 0) -> View {
return fitVerticallyToSuperview(padding)
}
/// To apply\add same leading, trailing, top and bottom pin constraints to superview with optional content inset.
@available(*, deprecated: 1.2, message: "Use 'fitToSuperview(contentInset:)' instead")
@discardableResult public final func applyConstraintFitToSuperview(contentInset inset: EdgeInsets) -> View {
return fitToSuperview(contentInset:inset)
}
}