You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Merges the provided ``LayoutConstraints`` with a current instance.
23
+
///
24
+
/// > Note: If the current instance and the provided instance have the same non-nil constraint, the constraint in the current instance will be overridden with a constraint from the provided instance.
25
+
/// - Parameter constraint: ``LayoutConstraints`` that should be merged with the current instance.
Copy file name to clipboardExpand all lines: Sources/AutoLayout/LayoutConstraints.swift
+22-12Lines changed: 22 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,35 @@
1
1
import UIKit
2
2
3
-
/// Contains constraints of the view.
3
+
/// A structure that holds references to various layout constraints applied to a view.
4
+
///
5
+
/// The `LayoutConstraints` struct is used to store the constraints created by layout helper methods. Each property corresponds to a specific type of constraint that has been applied.
6
+
///
7
+
/// This struct allows you to easily access and manipulate specific constraints after they have been applied to a view, facilitating adjustments or deactivations as needed.
8
+
///
9
+
/// ```swift
10
+
/// let constraints = myView.edges(16)
11
+
/// constraints.top?.constant = 20 // Adjust the top constraint's constant
12
+
/// constraints.trailing?.isActive = false // Deactivate the trailing constraint
13
+
/// ```
4
14
publicstructLayoutConstraints{
5
-
/// Top constraint.
15
+
/// The top edge constraint.
6
16
publicvartop:NSLayoutConstraint?
7
-
/// Leading constraint.
17
+
/// The leading edge constraint.
8
18
publicvarleading:NSLayoutConstraint?
9
-
/// Bottom constraint.
19
+
/// The bottom edge constraint.
10
20
publicvarbottom:NSLayoutConstraint?
11
-
/// Trailing constraint.
21
+
/// The trailing edge constraint.
12
22
publicvartrailing:NSLayoutConstraint?
13
-
/// Vertical constraint.
23
+
/// The vertical alignment constraint (e.g., center Y).
14
24
publicvarvertical:NSLayoutConstraint?
15
-
/// Horizontal constraint.
25
+
/// The horizontal alignment constraint (e.g., center X).
16
26
publicvarhorizontal:NSLayoutConstraint?
17
-
/// Width constraint.
27
+
/// The width constraint.
18
28
publicvarwidth:NSLayoutConstraint?
19
-
/// Height constraint.
29
+
/// The height constraint.
20
30
publicvarheight:NSLayoutConstraint?
21
31
22
-
/// Array of all constraints.
32
+
/// Array with all constraints.
23
33
publicvarallConstraints:[NSLayoutConstraint?]{
24
34
return[
25
35
self.top,
@@ -54,12 +64,12 @@ public struct LayoutConstraints {
Copy file name to clipboardExpand all lines: Sources/AutoLayout/UIView+Layout.swift
+134-8Lines changed: 134 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,14 @@
1
1
import UIKit
2
2
3
3
extensionUIView{
4
+
/// Constrains the view's leading anchor to the leading anchor of another view or its superview.
5
+
///
6
+
/// - Parameters:
7
+
/// - padding: The distance between the leading edges of the two views.
8
+
/// - view: The view to which the leading edge will be constrained. If `nil`, the view's superview is used.
9
+
/// - safeArea: A Boolean indicating whether to constrain to the `safeAreaLayoutGuide` of the other view. If `true`, the constraint respects the safe area.
10
+
///
11
+
/// - Returns: A ``LayoutConstraints`` object containing the leading edge constraint.
4
12
@discardableResult
5
13
publicfunc leading(
6
14
_ padding:CGFloat=0,
@@ -25,6 +33,14 @@ extension UIView {
25
33
returnLayoutConstraints(leading: constraint)
26
34
}
27
35
36
+
/// Constrains the view's trailing anchor to the trailing anchor of another view or its superview.
37
+
///
38
+
/// - Parameters:
39
+
/// - padding: The distance between the trailing edges of the two views.
40
+
/// - view: The view to which the trailing edge will be constrained. If `nil`, the view's superview is used.
41
+
/// - safeArea: A Boolean indicating whether to constrain to the `safeAreaLayoutGuide` of the other view. If `true`, the constraint respects the safe area.
42
+
///
43
+
/// - Returns: A ``LayoutConstraints`` object containing the trailing edge constraint.
28
44
@discardableResult
29
45
publicfunc trailing(
30
46
_ padding:CGFloat=0,
@@ -49,6 +65,14 @@ extension UIView {
49
65
returnLayoutConstraints(trailing: constraint)
50
66
}
51
67
68
+
/// Constrains the view's top anchor to the top anchor of another view or its superview.
69
+
///
70
+
/// - Parameters:
71
+
/// - padding: The distance between the top edges of the two views.
72
+
/// - view: The view to which the top edge will be constrained. If `nil`, the view's superview is used.
73
+
/// - safeArea: A Boolean indicating whether to constrain to the `safeAreaLayoutGuide` of the other view. If `true`, the constraint respects the safe area.
74
+
///
75
+
/// - Returns: A ``LayoutConstraints`` object containing the top edge constraint.
52
76
@discardableResult
53
77
publicfunc top(
54
78
_ padding:CGFloat=0,
@@ -73,6 +97,14 @@ extension UIView {
73
97
returnLayoutConstraints(top: constraint)
74
98
}
75
99
100
+
/// Constrains the view's bottom anchor to the bottom anchor of another view or its superview.
101
+
///
102
+
/// - Parameters:
103
+
/// - padding: The distance between the bottom edges of the two views.
104
+
/// - view: The view to which the bottom edge will be constrained. If `nil`, the view's superview is used.
105
+
/// - safeArea: A Boolean indicating whether to constrain to the `safeAreaLayoutGuide` of the other view. If `true`, the constraint respects the safe area.
106
+
///
107
+
/// - Returns: A ``LayoutConstraints`` object containing the bottom edge constraint.
76
108
@discardableResult
77
109
publicfunc bottom(
78
110
_ padding:CGFloat=0,
@@ -99,6 +131,14 @@ extension UIView {
99
131
}
100
132
101
133
extensionUIView{
134
+
/// Constrains the view's leading and trailing edges to those of another view or its superview, effectively stretching it horizontally.
135
+
///
136
+
/// - Parameters:
137
+
/// - padding: The distance between the view's edges and the other view's edges.
138
+
/// - view: The view to which the horizontal edges will be constrained. If `nil`, the view's superview is used.
139
+
/// - safeArea: A Boolean indicating whether to constrain to the `safeAreaLayoutGuide` of the other view. If `true`, the constraints respect the safe area.
140
+
///
141
+
/// - Returns: A ``LayoutConstraints`` object containing the leading and trailing constraints.
102
142
@discardableResult
103
143
publicfunc horizontally(
104
144
_ padding:CGFloat=0,
@@ -111,6 +151,14 @@ extension UIView {
111
151
}
112
152
}
113
153
154
+
/// Constrains the view's top and bottom edges to those of another view or its superview, effectively stretching it vertically.
155
+
///
156
+
/// - Parameters:
157
+
/// - padding: The distance between the view's edges and the other view's edges.
158
+
/// - view: The view to which the vertical edges will be constrained. If `nil`, the view's superview is used.
159
+
/// - safeArea: A Boolean indicating whether to constrain to the `safeAreaLayoutGuide` of the other view. If `true`, the constraints respect the safe area.
160
+
///
161
+
/// - Returns: A ``LayoutConstraints`` object containing the top and bottom constraints.
114
162
@discardableResult
115
163
publicfunc vertically(
116
164
_ padding:CGFloat=0,
@@ -125,6 +173,14 @@ extension UIView {
125
173
}
126
174
127
175
extensionUIView{
176
+
/// Constrains all four edges of the view to another view or its superview, optionally with padding and safe area considerations.
177
+
///
178
+
/// - Parameters:
179
+
/// - padding: The distance between the view's edges and the other view's edges.
180
+
/// - view: The view to which the edges will be constrained. If `nil`, the view's superview is used.
181
+
/// - safeArea: A Boolean indicating whether to constrain to the `safeAreaLayoutGuide` of the other view. If `true`, the constraints respect the safe area.
182
+
///
183
+
/// - Returns: A ``LayoutConstraints`` object containing top, leading, bottom and trailing constraints.
128
184
@discardableResult
129
185
publicfunc allEdges(
130
186
_ padding:CGFloat=0,
@@ -139,7 +195,13 @@ extension UIView {
139
195
}
140
196
141
197
extensionUIView{
142
-
/// Align the view after the passed view.
198
+
/// Constrains the view's leading anchor to the trailing anchor of another view, positioning it after the specified view horizontally.
199
+
///
200
+
/// - Parameters:
201
+
/// - view: The view after which this view will be positioned.
202
+
/// - padding: The space between the trailing edge of the specified view and the leading edge of this view.
203
+
///
204
+
/// - Returns: A ``LayoutConstraints`` object containing the leading edge constraint.
143
205
@discardableResult
144
206
publicfunc after(
145
207
_ view:UIView,
@@ -156,7 +218,13 @@ extension UIView {
156
218
returnLayoutConstraints(leading: constraint)
157
219
}
158
220
159
-
/// Align the view before the passed view.
221
+
/// Constrains the view's trailing anchor to the leading anchor of another view, positioning it before the specified view horizontally.
222
+
///
223
+
/// - Parameters:
224
+
/// - view: The view before which this view will be positioned.
225
+
/// - padding: The space between the leading edge of the specified view and the trailing edge of this view.
226
+
///
227
+
/// - Returns: A ``LayoutConstraints`` object containing the trailing edge constraint.
160
228
@discardableResult
161
229
publicfunc before(
162
230
_ view:UIView,
@@ -173,7 +241,13 @@ extension UIView {
173
241
returnLayoutConstraints(trailing: constraint)
174
242
}
175
243
176
-
/// Align the view below the passed view.
244
+
/// Constrains the view's top anchor to the bottom anchor of another view, positioning it below the specified view vertically.
245
+
///
246
+
/// - Parameters:
247
+
/// - view: The view below which this view will be positioned.
248
+
/// - padding: The space between the bottom edge of the specified view and the top edge of this view.
249
+
///
250
+
/// - Returns: A ``LayoutConstraints`` object containing the top edge constraint.
177
251
@discardableResult
178
252
publicfunc below(
179
253
_ view:UIView,
@@ -190,7 +264,13 @@ extension UIView {
190
264
returnLayoutConstraints(bottom: constraint)
191
265
}
192
266
193
-
/// Align the view above the passed view.
267
+
/// Constrains the view's bottom anchor to the top anchor of another view, positioning it above the specified view vertically.
268
+
///
269
+
/// - Parameters:
270
+
/// - view: The view above which this view will be positioned.
271
+
/// - padding: The space between the top edge of the specified view and the bottom edge of this view.
272
+
///
273
+
/// - Returns: A ``LayoutConstraints`` object containing the bottom edge constraint.
194
274
@discardableResult
195
275
publicfunc above(
196
276
_ view:UIView,
@@ -209,6 +289,12 @@ extension UIView {
209
289
}
210
290
211
291
extensionUIView{
292
+
/// Sets the view's width to a specific value.
293
+
///
294
+
/// - Parameters:
295
+
/// - value: The width value.
296
+
///
297
+
/// - Returns: A ``LayoutConstraints`` object containing the width constraint.
0 commit comments