-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlexUI+UIView.swift
More file actions
179 lines (164 loc) · 6.68 KB
/
FlexUI+UIView.swift
File metadata and controls
179 lines (164 loc) · 6.68 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
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
//
// flex-ui
// Copyright © 2025 Space Code. All rights reserved.
//
import UIKit
public extension FlexUI where Component: UIView {
/// Sets the corner radius of the view.
///
/// - Parameter cornerRadius: The radius of the view's corners.
/// - Returns: The current instance of `FlexUI` for further configuration.
@discardableResult
@MainActor
func cornerRadius(_ cornerRadius: CGFloat) -> Self {
component.layer.cornerRadius = cornerRadius
return self
}
/// Enables or disables user interaction for the view.
///
/// - Parameter isEnabled: A boolean indicating whether user interaction should be enabled.
/// - Returns: The current instance of `FlexUI` for further configuration.
@discardableResult
@MainActor
func isUserInteractionEnabled(_ isEnabled: Bool) -> Self {
component.isUserInteractionEnabled = isEnabled
return self
}
/// Sets the background color of the view.
///
/// - Parameter color: The color to apply to the view's background.
/// - Returns: The current instance of `FlexUI` for further configuration.
@discardableResult
@MainActor
func backgroundColor(_ color: UIColor) -> Self {
component.backgroundColor = color
return self
}
/// Sets the border width of the view.
///
/// - Parameter width: The width to apply to the view's border.
/// - Returns: The current instance of `FlexUI` for further configuration.
@discardableResult
@MainActor
func borderWidth(_ width: CGFloat) -> Self {
component.layer.borderWidth = width
return self
}
/// Sets the border color of the view.
///
/// - Parameter color: The color to apply to the view's border.
/// - Returns: The current instance of `FlexUI` for further configuration.
@discardableResult
@MainActor
func borderColor(_ color: UIColor) -> Self {
component.layer.borderColor = color.cgColor
return self
}
/// Enables or disables clipping to the bounds of the view.
///
/// - Parameter isEnabled: A boolean indicating whether the view should clip to its bounds.
/// - Returns: The current instance of `FlexUI` for further configuration.
@discardableResult
@MainActor
func masksToBounds(_ isEnabled: Bool) -> Self {
component.layer.masksToBounds = isEnabled
return self
}
/// Sets the masked corners for the view.
///
/// - Parameter maskedCorners: A set of corners to mask (e.g., `.layerMinXMinYCorner`).
/// - Returns: The current instance of `FlexUI` for further configuration.
@discardableResult
@MainActor
func maskedCorners(_ maskedCorners: CACornerMask) -> Self {
component.layer.maskedCorners = maskedCorners
return self
}
/// Sets a custom mask layer for the view.
///
/// - Parameter mask: A `CALayer` to be applied as the mask for the view.
/// - Returns: The current instance of `FlexUI` for further configuration.
@discardableResult
@MainActor
func mask(_ mask: CALayer?) -> Self {
component.layer.mask = mask
return self
}
/// Applies a 3D transformation to the view's layer.
///
/// - Parameter transform: The transformation to apply to the view's layer.
/// - Returns: The current instance of `FlexUI` for further configuration.
@discardableResult
@MainActor
func transform(_ transform: CATransform3D) -> Self {
component.layer.transform = transform
return self
}
/// Applies a transformation to the component.
/// - Parameter transform: A `CGAffineTransform` that modifies the component's position, rotation, scale, or skew.
/// - Returns: The modified instance of `Self` to allow method chaining.
/// - Note: The `@discardableResult` attribute allows ignoring the returned value.
/// The `@MainActor` attribute ensures the method runs on the main thread.
@discardableResult
@MainActor
func transform(_ transform: CGAffineTransform) -> Self {
component.transform = transform
return self
}
/// Sets the visibility of the component.
/// - Parameter isHidden: A Boolean value that determines whether the component is hidden.
/// - Returns: The modified instance of `Self` to allow method chaining.
/// - Note: The `@discardableResult` attribute allows ignoring the returned value.
/// The `@MainActor` attribute ensures the method runs on the main thread.
@discardableResult
@MainActor
func isHidden(_ isHidden: Bool) -> Self {
component.isHidden = isHidden
return self
}
/// Sets the transparency of the component.
/// - Parameter alpha: A `CGFloat` value between 0.0 (completely transparent) and 1.0 (completely opaque).
/// - Returns: The modified instance of `Self` to allow method chaining.
/// - Note: The `@discardableResult` attribute allows ignoring the returned value.
/// The `@MainActor` attribute ensures the method runs on the main thread.
@discardableResult
@MainActor
func alpha(_ alpha: CGFloat) -> Self {
component.alpha = alpha
return self
}
/// Sets the content hugging priority for the specified axis.
/// Content hugging determines how likely the view is to shrink below its intrinsic content size.
/// A higher priority means the view resists growing beyond its content size.
///
/// - Parameters:
/// - priority: The priority value to set.
/// - axis: The axis (`.horizontal` or `.vertical`) on which to apply the priority.
/// - Returns: The current instance, allowing method chaining.
@discardableResult
@MainActor
func setContentHuggingPriority(
_ priority: UILayoutPriority,
for axis: NSLayoutConstraint.Axis
) -> Self {
component.setContentHuggingPriority(priority, for: axis)
return self
}
/// Sets the content compression resistance priority for the specified axis.
/// Compression resistance determines how likely the view is to shrink below its intrinsic content size under compression.
/// A higher priority means the view resists being made smaller than its content size.
///
/// - Parameters:
/// - priority: The priority value to set.
/// - axis: The axis (`.horizontal` or `.vertical`) on which to apply the priority.
/// - Returns: The current instance, allowing method chaining.
@discardableResult
@MainActor
func setContentCompressionResistancePriority(
_ priority: UILayoutPriority,
for axis: NSLayoutConstraint.Axis
) -> Self {
component.setContentCompressionResistancePriority(priority, for: axis)
return self
}
}