File tree 1 file changed +16
-1
lines changed
bk2ch28AppendixB/bk2ch40AppendixB
1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ extension UIView {
146
146
}
147
147
148
148
// not in the book, but maybe they should be:
149
- // utilities for understandind an untouchable view
149
+ // utilities for understanding an untouchable view
150
150
151
151
extension UIView {
152
152
@objc func reportNoninteractiveSuperview( ) {
@@ -174,6 +174,21 @@ extension UIView {
174
174
}
175
175
}
176
176
177
+ // utility for shortening constraint creation
178
+ // I'm not big on this kind of thing, but this is so common it seems to need something
179
+
180
+ extension UIView {
181
+ func pinToSuperview( _ insets: NSDirectionalEdgeInsets = . zero) {
182
+ guard let sup = self . superview else { return }
183
+ self . translatesAutoresizingMaskIntoConstraints = false
184
+ self . topAnchor. constraint ( equalTo: sup. topAnchor, constant: insets. top) . isActive = true
185
+ self . trailingAnchor. constraint ( equalTo: sup. trailingAnchor, constant: - insets. trailing) . isActive = true
186
+ self . leadingAnchor. constraint ( equalTo: sup. leadingAnchor, constant: insets. leading) . isActive = true
187
+ self . bottomAnchor. constraint ( equalTo: sup. bottomAnchor, constant: - insets. bottom) . isActive = true
188
+ }
189
+ }
190
+
191
+
177
192
178
193
extension UIControl {
179
194
func addAction( for event: UIControl . Event ,
You can’t perform that action at this time.
0 commit comments